Ubuntu – How to set up an hourly Cron job to run `grive` from `/etc/cron.hourly`

crongrive

I added the file grive.sh to /etc/cron.daily but the command doesn't seem to be running. I also copied it to /etc/cron.hourly but there has been no change to my Google Drive directory only. The file has only three lines:

#! /bin/sh
cd /media/james/Seagate Expansion Drive/GD
grive

The permissions are read-only so I'll update those.

I used /etc/cron.hourly# chmod u+rwx grive.sh, but then when I check the permissions for the file in Nautilus, they are unchanged—I don't know why.

I can run grive manually from the terminal, and the files sync locally and online.

root@james-Streacom:/etc/cron.hourly# grep CRON /var/log/syslog
Feb  1 09:17:02 james-Streacom CRON[8696]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 10:17:01 james-Streacom CRON[10958]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 11:17:01 james-Streacom CRON[12897]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 12:17:01 james-Streacom CRON[15307]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 13:17:01 james-Streacom CRON[17043]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 14:17:01 james-Streacom CRON[17354]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  1 15:17:01 james-Streacom CRON[17705]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
root@james-Streacom:/etc/cron.hourly# cd / && run-parts --report /etc/cron.hourly
root@james-Streacom:/# bash -c "cd / && run-parts --report /etc/cron.hourly"
root@james-Streacom:/#

Note that this may be a duplicate of The cron job doesn't work when put in `/etc/cron.hourly/` but work when defined in `crontab -e`, I'm just going through those steps.

I added echo test >/tmp/foobar.tmp to the last line of the script.

root@james-Streacom:/etc/cron.hourly# grep 'cron\.hourly' /etc/crontab
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly

/temp/foobar.tmp doesn't exist.

I tried to actually run # cd /media/james/Seagate Expansion Drive/GD, and got the error -su: cd: too many arguments. I then changed the cd line in the script to cd /media/james/"Seagate Expansion Drive"/GD.

$ echo test >/tmp/foobar.tmp does create the file with test in it.
# echo test2 >/tmp/foobar.tmp overwrites test with test2.

Best Answer

Aside from the unquoted whitespace in your original script (which you seem to have corrected) the issue is likely with the naming of your script.

According to the DEBIAN SPECIFIC section of man cron:

   As  described  above, the files under these directories have to be pass
   some sanity checks including the following: be executable, be owned  by
   root,  not  be  writable  by  group or other and, if symlinks, point to
   files owned by root. Additionally, the file names must conform  to  the
   filename  requirements  of  run-parts: they must be entirely made up of
   letters, digits and can only  contain  the  special  signs  underscores
   ('_')  and  hyphens  ('-').  Any  file  that  does not conform to these
   requirements will not be executed by run-parts.  For example, any  file
   containing  dots  will  be  ignored.  This is done to prevent cron from
   running any of the files that are left by the Debian package management
   system when handling files in /etc/cron.d/ as configuration files (i.e.
   files ending in .dpkg-dist, .dpkg-orig, and .dpkg-new).

Since grive.sh has a dot in its name, run-parts will ignore it.

Related Question