Google Drive is an excellent choice for storing files in the cloud. It comes with good support for Windows, OsX and Android. It does however lack support for Linux at the moment, though Google have promised Linux support in the future.
We are for now left with community driven alternatives, Grive is one such great alternative. It works very well, even though it lacks on important feature; automatic sync on folder changes.
There are some sites that have nice descriptions on how to overcome this with periodic syncs. This is good enough most of the times, but it would be better if syncing could be triggered automatically on folder changes, including sub-folders.
There is actually already an existing package that can detect folder changes; Inotify. I have written a small script that utilizes that to detect folder changes and trigger an execution of Grive. That script is detailed full below. It’s small, simple and effective. Just add it to your automatic startup programs.

This is how you do that in Gome2 or Mate.
Pre reqs:
Grive
inotify-tools
Follow this link for a guide on how to set up periodic syncs with Grive. It also details how to install Grive if you need help with that. I will neglect to describe that.
The below script should be added to your Startup Applications, save the script as grive.sh and add it.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash # Google Drive Grive script that syncs your Google Drive folder on change # This functionality is currently missing in Grive and there are still no # official Google Drive app for Linux comming from Google. # # This script will only detect local changes and trigger a sync. Remote # changes will go undetected and are probably still best sync on a periodic # basis via cron. # # Kudos to Nestal Wan for writing the excellent Grive software # Also thanks to Google for lending some free disk space to me # # Peter Österberg, 2012 GRIVE_COMMAND_WITH_PATH=~/bin/grive # Path to your grive binary, change to match your system GDRIVE_PATH=~/GDrive # Path to the folder that you want to be synced TIMEOUT=600 # Timeout time in seconds, for periodic syncs. Nicely pointed out by ivanmacx while true do inotifywait -t $TIMEOUT -e modify -e move -e create -e delete -r $GDRIVE_PATH cd $GDRIVE_PATH && $GRIVE_COMMAND_WITH_PATH done |
the ‘&&’ in your command is translated to ‘&&’ you should fix that.
Also you should mention that we have to adjust the variables
Thank you for pointing out that!
If you add a timeout variable:
TIMEOUT=600
and change the inotifywait command to:
inotifywait -t $TIMEOUT -e modify -e move -e create -e delete -r $GDRIVE_PATH
then it will do a check at least every ten minutes, (or whatever timeout you set in seconds) so you don’t need a separate cron job and you also avoid the risk of script and cron job both running grive simultaneously.
That’s valuable feedback. Thank you! I will update with the information you suggested.
Actually I’ve been tinkering with this for a bit now and ended up with this:
GRIVE_COMMAND_WITH_PATH=grive # Path to your grive binary, change to match your system
GDRIVE_PATH=~/GoogleDrive # Path to the folder that you want to be synced
LOGFILE=~/applications/grive/grive.log
STARTTIME=$(date +”%D-%T”)
echo “Starting grive.sh at $STARTTIME” >> $LOGFILE
if [
pgrep -c grsync.sh-gt 1 ]; then # is grsync.sh running twiceecho “grsync.sh is already running, exiting” >> $LOGFILE # if so, then log this
exit # and exit
fi
# monitor relevant inotify watches on $GDRIVE_PATH and act on any that occur
inotifywait -m -e modify -e delete -e move -e create -r $GDRIVE_PATH | while read LINE; do
if [[ $LINE != *.grive* ]]; then #ignore grive local status updates
if [
pgrep -c grive-eq 0 ] ; then # make sure grive is not already runningecho $(date +”%D-%T”)$’\n’$LINE$’\n’”Starting Grive” >> $LOGFILE
cd $GDRIVE_PATH && $GRIVE_COMMAND_WITH_PATH >> $LOGFILE 2>&1 # run grive
else
echo “grive already running, not running again” >> $LOGFILE
fi
else
echo “Ignored $LINE” >> $LOGFILE
fi
done
This seems to be working and it avoids repeatedly creating the inotify watches. Also it doesn’t run grive when the .grive and .grive_status files are updated by grive. The only drawback is that it runs the full Grive check every time you update a file, so if you’re editing a document and saving as you go it’s constantly running Grive. However that is inherent to Grive rather than this script so can’t be helped for now.
Then I added a cron job which updates a hidden .update file in the relevant directory every 15 minutes to force Grive to run and therefore check the remote files at least that often:
*/15 * * * * echo $(date +”%D-%T”) > /home/ivan/GoogleDrive/.update
This all does what I need for now. Hope it’s helpful.
Sorry, I’m going to stop hijacking this page until I’ve tested more thoroughly. There are two flaws with what I posted above. The cron job was failing until I put the command out into a bash script instead of directly in the crontab. Also the main script seems to get stuck in a loop if there’s a remote update of the Google Drive, because that causes the local files to get updated, which triggers an inotify event, which triggers grive. Not sure why it loops rather than just doing an extra sync, but it seems to.
I think your original solution was probably better, perhaps with my crontab update trigger. I can’t delete my comment, though, unfortunately.
I will leave your comment here anyway. It’s inspiring to see what you are aiming for. Someone else might help you debug it. =) I will update if you get to a final solution. Thank you for the efforts!!