0

I have a python file that has to be run with sudo elevation every 6 hours.

I created the cronjob using sudo crontab -e and then added the entry:

0 */6 * * * cd /home/timeflow/backup && sudo /usr/bin/python3 /home/timeflow/backup/backup_db.py

However, this file is never ran. I have also tried removing sudo from sudo /usr/bin/python3 home/timeflow/backup/backup_db.py, however this does nothing as well. For clarity:

0 */6 * * * cd /home/timeflow/backup && /usr/bin/python3 /home/timeflow/backup/backup_db.py

I have no idea why this is not working. I tried to do a smaller job, by creating a random python file in the same repo to no avail. The entry was:

* */6 * * * touch /home/timeflow/test.py
chxnge
  • 1
  • 1
    Are you really running 14.04, which is now ~3 years past end-of-life? Is your home directory encrypted? Does /var/log/syslog show any entries related to these cronjobs? Also try the answers in https://askubuntu.com/q/23009/158442 – muru Jun 01 '22 at 07:49
  • Only supported releases of Ubuntu (standard or public support) are on-topic for this site. Ubuntu 14.04 LTS is EOL (end-of-life) thus off-topic, and Ubuntu 14.04 ESM is in extended support and supported by Canonical via Ubuntu Advantage thus also off-topic here. Refer https://askubuntu.com/help/on-topic https://help.ubuntu.com/community/EOLUpgrades https://fridge.ubuntu.com/2019/05/02/ubuntu-14-04-trusty-tahr-reached-end-of-life-on-april-25-2019-esm-available/ You didn't specifically mention a release; but you've tagged your release as an off-topic release – guiverc Jun 01 '22 at 07:50
  • @muru @guiverc Sorry that was a mis-click. I am running 20.04. /var/log/syslog seems to show that the cronjobs are running properly. – chxnge Jun 01 '22 at 08:03
  • One way to troubleshoot this is to write a script containing three commands: first, echo something "I have started", and then include the cd and python3 commands. Modify the python program to print debugging messages to sysout. Have cron run that script instead, and redirect sysout and syserr to a log file. – Jos Jun 01 '22 at 09:03

0 Answers0