0

I need to set up cron job for python script scheduled at 08:00 15:00 and 18:00 IST

My python location is

/usr/bin/python3

and script location is

~/Documents/Python/script.py

I have tried the following solutions:

  1. How to schedule python script in a folder using crontab

  2. Schedule python script

  3. https://stackoverflow.com/questions/8727935/execute-python-script-via-crontab/8728014

but not working.

1 Answers1

4

This information is not as easy to find as usual, but the full documention can be viewed by doing:

man 5 crontab

which reveals this:

          field          allowed values
          -----          --------------
          minute         0-59
          hour           0-23
          day of month   1-31
          month          1-12 (or names, see below)
          day of week    0-7 (0 or 7 is Sun, or use names)

There is also a reminder of these fields at the top of every new crontab, but you may have deleted that:

# m h  dom mon dow   command

So, in order to run your script at 8:00, 15:00 and 18:00 on weekdays, do

0 8,15,18 * * 1-5 /usr/bin/python3 /home/[username]/Documents/Python/script.py

where 1-5 means Monday through Friday.

You need to fill in your own username, as cron does not understand the ~shortcut.

Jos
  • 29,224
  • Cron job not executing, I have changed the timing for trial:0 8,15,19 * * 1-5 /usr/bin/python /home/[username]/Documents/Python/script.py – Akshat Zala May 07 '20 at 14:12
  • Look in /var/log/syslog to see why the cron job didn't run. – Jos May 07 '20 at 14:15