Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I am trying to implement a watchdog script which I basically got from here.

Script works fine, starts up process if not running, does nothing if running. Now implementation into crontab gives me headaches!

Opened crontab in leafpad... (what are those leading nubers for? those aren't mentioned anywhere...) so I added */5 * * * * root /path/to/watchdog/script

For my understanding cron should now call up my watchdog script every 5min (on 5, 10, etc.) But it doesn't.

Help appreciated, Lars

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted
  1. Be sure that the crontab file is not executable or writable by other users.
  2. You should edit the file with crontab -e filename rather than with a general purpose editor.
  3. cron needs to be told to re-read crontabs after a modification thereto, with SIGHUP. I believe (but RTM to be sure) that crontab -e will send the signal but if you use another method to edit the file, you'll have to do it yourself with kill -HUP PID
share|improve this answer
    
per #3: man cron: "Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed." –  abolotnov Feb 6 '13 at 13:09
    
pi@raspberrypi ~ $ sudo crontab -e no crontab for root - using an empty one –  user5875 Feb 7 '13 at 17:11
add comment

Remember that cron uses the system time zone which by default I think is UTC. Therefore, you might be expecting things to happen in a different time zone. Confirm your time zone by using the command cat /etc/timezone

share|improve this answer
add comment

Are you editing /etc/crontab or /var/spool/cron/crontabs/*?

can you copy the output for the whole file?

cat /etc/crontab

Do you have the root user on the system?

cat /etc/passwd|cut -d":" -f1|grep root

If you are editing individual crontabs, you don't need to specify the user and should not edit the file directly and instead use crontab -l to view your crons and crontab -e to edit them.

share|improve this answer
    
editing /etc/crontab –  user5875 Feb 7 '13 at 17:06
    
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 18 */5 * * * * root /etc/bin/watchdog 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$ 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$ 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --repo$ –  user5875 Feb 7 '13 at 17:07
1  
it's badly formatted, I suggest you either update your question with the content or put it on pastebin or similar side and share a link here. –  abolotnov Feb 7 '13 at 20:37
add comment

Please check if there is a newline character at the end, as it should. I experienced problems if the last line was not empty.

You are correct in your understanding, it should execute every 5 minutes.

From Manpage as mentiond by abolotnov:

cron requires that each entry in a crontab end in a newline character. If the last entry in a crontab is missing the newline, cron will consider the crontab (at least partially) broken and refuse to install it.

share|improve this answer
1  
Are you suggesting to add or remove the new line character? man crontab: "cron requires that each entry in a crontab end in a newline character. If the last entry in a crontab is missing the newline, cron will consider the crontab (at least partially) broken and refuse to install it." –  abolotnov Feb 6 '13 at 13:06
    
I will edit my answer to make it clear –  macrojames Feb 6 '13 at 14:10
    
Better yet, edit the file with crontab -e filename rather than with a general purpose editor. –  CPRitter Feb 9 '13 at 12:57
add comment

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.