0

Crontab working fine when set to run every minute like that:

* * * * * /usr/bin/python3 python/orders_processor.py

Crontab not working when set for specific time like that:

00 8 * * * /usr/bin/python3 python/orders_processor.py

When I run it from root direcotry it also works fine.

/usr/bin/python3 python/orders_processor.py

I tried different time settings and it seems to be only working when I am manipulating the minutes. When the script is runned it sends an email that is how I know it is working or not working.

  • 1
    Probably your problem is using 00 instead of just 0. Alternatively, you didn't make it clear if you've actually waited until the specified time. – Wildcard Mar 27 '24 at 19:31
  • What timezone are you in? It is possible that crond was started in UCT, and needs to be restarted to pick up TZ changes: IST is a specific problem case. I have test cases 00 00-23 * * 1-5 and 00-09,44-59 * * * 1-5 which work just fine. (Linux Mint 19.3). – Paul_Pedant Mar 27 '24 at 22:04
  • 1
    For clarity, at what time are you expecting the cronjob 00 8 * * * to run? – Chris Davies Mar 28 '24 at 10:03
  • 1
    @Wildcard one can safely use 00 for minutes without issue – Chris Davies Mar 28 '24 at 10:03
  • Note the real problem, but why do you use absolute path on python (probably you see in some best practices), but not on the script? Are you sure that crontab is setting the correct working directory? – Giacomo Catenazzi Mar 28 '24 at 10:14
  • What Linux distro and version are you on? Your 00 8 * * * is valid in my Mint 19.3; Crontab Guru confirms "At 08:00"; this simple format has been valid forever; and the crontab editor validates any changes. (You are using crontab -e as your user, right?) So you are either not editing the crontab you think you are, or your testing method is faulty. Try testing with 00 * * * * date >> /tmp/myCron.log and tail -f the log. I am also suspicious of that relative pathname.py -- cron does not source your profiles, so your PATH is not set (along with many other omissions). – Paul_Pedant Mar 28 '24 at 10:16
  • What's the exact command you're using to create this crontab entry? If you're editing a file, what file and in what directory? – Chris Davies Mar 28 '24 at 11:31

2 Answers2

0

Separate the crontab issue from the probable python issue.

Use this crontab entry to prove the test methodology is valid and effective. (Obviously, replace myUser with your own username.) I put all the time parameters through Crontab Guru and my own cron file.

* * * * * { date; echo $HOME; echo $PATH; env; } >> /home/myUser/Cron.env 2>&1

Then move up to a minutes specification (every three minutes to save you some waiting). If these work, then the simpler one will too. The comments can go in the crontab too.

#.. Every hour, on the hour. 
00  * * * * { date; echo $HOME; echo $PATH; env; } >> /home/myUser/Cron.env 2>&1
#.. At minutes 1, 4, 7, 10, .. , 58
01-59/3 * * * * { date; echo $HOME; echo $PATH; env; } >> /home/myUser/Cron.env 2>&1

Once you have the time regime working as you wish, you can check the Python part works with the (skeleton) environment that cron provides.

Paul_Pedant
  • 8,679
-1

Examples From Your Own Question

  1. * * * * * /usr/bin/python3 python/orders_processor.py - Execute the script every minute of every hour of every month of the year every day of the month.

  2. 00 8 * * * /usr/bin/python3 python/orders_processor.py - Execute the script every day of every month at 8AM (top of the hour) local time.


Each asterisk has a specific meaning depending on your cron daemon. See my answer for Do Spaces Matter in Crontab for what they mean. Did you test it at 7:59A local time?

eyoung100
  • 6,252
  • 23
  • 53