Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Iain, Falcon Momot, TheCleaner, MadHatter, MDMarra Jul 28 '13 at 17:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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 2:44

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