0

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.

2

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.

  • Thanks, I renamed the file to grive, and will wait an hour and see whether it runs. – James Ray Feb 2 '18 at 7:40
0

I don't really get your question, although in my experience some commands doesn't work as expected when you add them into a script and put in a cronjob.

I'd start by adding it to new file in /etc/cron.d/test as following (I'll configure it every 5 minutes just to get some logs for testing purposes):

# m h  dom mon dow user command
*/5 * * * * root [DIR_TO_SCRIPT]/grive.sh >> /var/log/grivesh.log 2>&1

Please see stdout in /var/log/grivesh.log, once you have it analized you can have cronjob configured once every hour like this (e.g. at minute 5 every hour):

# m h  dom mon dow user command
5 * * * * root [DIR_TO_SCRIPT]/grive.sh >> /var/log/grivesh.log 2>&1

It is necesary to have it in /etc/cron.hourly/? Don't you preefer to have it in /etc/cron.d/ or in a crontab for your user?

Regards,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.