0

This evening I have been playing with cron for the first time, and have started experiencing strange results. The script that I am trying to run is a watchdog that allows me to manage a couple other scripts with a web interface. When I run the watchdog script from a shell, sudo ./watchdog.py it works fine every time, and starts the scripts it is supposed to. When I add it to crotab, sudo crontab -e with the line */1 * * * * /home/user/watchdog.py, it does not start them, or they crash shortly after starting. These scripts do need to run as root, so I have also tried */1 * * * * sudo /home/user/watchdog.py, but nothing changed.

My question is 2 part.

1: How do I troubleshoot this?

2: What causes this, and why?

Butters
  • 105
  • 5

1 Answers1

2

1: How do I troubleshoot this?

Start by recording stderr and stdout of your script to a file (although by default cron should be mailing you the output). You can do something like:

*/1 * * * * sudo /home/user/watchdog.py > /tmp/watchdog.log 2>&1

This will put any output generated by your script in /tmp/watchdog.log.

FYI: Note that */1 is identical to just * by itself.

2: What causes this, and why?

If the requiretty flag is set in /etc/sudoers, then sudo will only operate from a real TTY (e.g., from an interactive login session). That's not necessarily what's happening here but it's something to check. Look for a line along the lines of:

Defaults requiretty

in /etc/sudoers.

larsks
  • 41,276
  • 13
  • 117
  • 170
  • Thanks for the quick response! That got me going again. There was one relative file path I had missed at the very beginning of the project. – Butters Jul 28 '13 at 02:44