2

I have a shellscript in /etc/myprog/myscript.sh that I would like to run every week. Therefore I created a symbolic link in /etc/cron.weekly:

root@ip-10-190-199-197:/etc/cron.weekly# ls -ltr
total 8
-rwxr-xr-x 1 root root 895 2011-07-27 11:32 man-db
-rwxr-xr-x 1 root root 730 2011-09-24 14:55 apt-xapian-index
lrwxrwxrwx 1 root root  31 2011-11-17 05:36 myscript -> /etc/myprog/myscript.sh

To test it, I did:

cd /etc/cron.weekly
sudo ./myscript

It works perfect. However, the cronjob never actually runs for some reason. Do I need to do anything to activate cron.weekly?

The contents of my /etc/myprog/myscript.sh is:

cd /var/log/myprog/
/etc/myprog/updatescript.sh 1> `date '+/etc/myprog/logs/%Y-%m-%d-cran.log'` 2> `date '+/etc/myprog/logs/%Y-%m-%d-cran-warnings.log'`
Jeroen Ooms
  • 617
  • 2
  • 9
  • 27
  • Do you run the computer non-stop? Do *anacron* jobs run? Is the `/etc/myprog/myscript.sh` file owned by root? Do you see any messages in *syslog* when the job is supposed to run? Have you tested running it hourly or some other time frame than weekly? – arrange Dec 31 '11 at 11:40

1 Answers1

1

I suspect you need to add a shebang to the start of your script to help cron know what interpreter to use. So your script would become:

#!/bin/sh
cd /var/log/myprog/
/etc/myprog/updatescript.sh 1> `date '+/etc/myprog/logs/%Y-%m-%d-cran.log'` 2> `date '+/etc/myprog/logs/%Y-%m-%d-cran-warnings.log'`

Cron may not know much about paths and the like, so you need to give it more clues.

Hamish Downer
  • 19,013
  • 14
  • 70
  • 92