1

I'm running Debian 9. I log in as root and do crontab -e and add the following lines:

0 */2 * * * python /home/Folder1/Script.py
1 */2 * * * python /home/Folder2/Script.py
2 */2 * * * python /home/Folder3/Script.py
3 */2 * * * python /home/Folder4/Script.py

The script's don't run. I've also tried adding root before python to specify the user running the script. I believe this crontab is located in /var/spool/cron/crontabs/root but I'm not sure if that's the 'main' location. No errors or messages relating to the cron running are reported in /var/log/syslog. Nothing is reported in my postfix local mail. I've tried permissions 644 and 744 for the Python scripts.

This cron works when running on a user's crontab, but not root. I've tried this on a personal PC (amd64 Debian 9) and on a VPS (VPS Dime amd64 Debian 9).

  • 1
    Can you give us an the code of one of these scripts? I want to see if there is an issue with environment variables. You may also want to add some logging to the end of the cronjob. My guess is this has some sort of issue with PATH – EDubman Apr 18 '18 at 6:11
  • What error messages has cron sent you? Run the mail command (or read the file /var/mail/root) – roaima Apr 18 '18 at 8:12
  • You could save a lot of disk space by using 0-3 as the first column. You'll gain time to when you have to correct your crontab. – Gerard H. Pille Apr 18 '18 at 9:48
  • There's nothing in the script itself that prevents it from running when called by root? – Gerard H. Pille Apr 18 '18 at 10:10
1

You should first add the path for Python when using crontab.

Assuming this actually is the correct full location of the script, you need the following:

0 */2 * * * /usr/bin/python /home/Folder1/Script.py

You also need to verify environmental variables in your script are absolute paths, because keep in mind cronjobs will see these variables differently.

  • It's unlikely to be an issue with the interpreter's path, but more likely to be an issue with environment variables used by the script itself. – Kusalananda Apr 18 '18 at 6:27
  • @Kusalananda, nonsense, original crontab has no environment, EDubman is right. – Gerard H. Pille Apr 18 '18 at 9:47
  • @GerardH.Pille "No environment", really? Try running env >"$HOME/cron.env" in a cron job. Unless the system's default configuration has been totally disfigured, that should output PATH=/usr/bin:/bin to $HOME/cron.env along with other environment variables. – Kusalananda Apr 18 '18 at 9:56
  • @Kusalananda I stand corrected. – Gerard H. Pille Apr 18 '18 at 10:14
  • I forgot to mention that I already tried adding the full path of Python – GShocked Apr 18 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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