0

I am running Ubuntu 16.0.4.1 and have a cron job set up to run the following which just logs the time to a file...

* * * * * /usr/bin/python3 /root/python-cron-test/main.py > /dev/null 2>&1

However, nothing is actually happening. I can see in /var/log/syslog that the cron job is being called...

CRON[11871]: (root) CMD (/usr/bin/python3 /root/python-cron-test/main.py)

If I run the command from the command line it works just fine.

I ran a cron job to give me the env that the cron job runs and it prints out...

HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=en_US.UTF-8
SHELL=/bin/sh
PWD=/root

Running env from the terminal print out...

XDG_SESSION_ID=1713
SHELL=/bin/bash
USER=root
MAIL=/var/mail/root
PATH=/root/bin:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
_=/usr/bin/env

I've checked the status of cron and it's running, I've even restarted the daemon.

Can anyone give me ideas as to why it might not be working?

Thanks

  • are you using 'sudo' with crontab? – Philip Kirkbride Oct 12 '16 at 15:03
  • No I'm not using sudo – bencarter78 Oct 12 '16 at 15:12
  • 1
    Have you verified the permissions on the main.py script file (and the parent folder python-cron-test)? See this answer for other permission / python hints: stackoverflow.com/a/8728014/1876622 – HeyZiko Oct 12 '16 at 15:19

Your Answer

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

Browse other questions tagged or ask your own question.