Search code examples
pythoncron

Why is crontab not running a python script


This is how I configure crontab (by using crontab -e)

* * * * * /home/jeff/Desktop/scripts/job_pull_queue.sh >> /home/jeff/Desktop/scripts/log.txt

This is the content of /home/jeff/Desktop/scripts/job_pull_queue.sh

#!/bin/bash
echo "Running job_pull_queue.sh @ $(date)"
cd /home/jeff/Documents/code/some_project
echo $(printenv)
/home/jeff/miniconda3/bin/python -m util.main

Now the problem is, when running ./job_pull_queue.sh in the terminal, it works, but I can tell from the log file that crontab never executes that last line /home/jeff/miniconda3/bin/python -m util.main (I can see the result from the previous echo in the log file, but not the python script itself), what happened? How do I fix it?

Update: here's the result from printenv when ran by crontab

SHELL=/bin/sh PWD=/home/jeff/Documents/code/some_project LOGNAME=jeff HOME=/home/jeff LANG=en_US.UTF-8 SHLVL=0 PATH=/usr/bin:/bin OLDPWD=/home/jeff _=/usr/bin/printenv

Solution

  • Ok...

    My Python script reads several env variables from my user profile, and of course, these variables don't exist when crontab is running the script...

    And I don't have detection/logging in place so I didn't know env variables are missing.