Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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'`
share|improve this question
    
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 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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