Python Forum

Full Version: Py script that triggers ever 3 hours, but only between 9:15 am to 3:30 pm, Mon to Fri
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm running a AWS Ubuntu server with python. How do I run a script that triggers every 3 hours, from 9:15AM to 3:30 PM, Monday to Friday.

I'm looking for a direction.
The classic way in Unix and Linux to schedule commands is cron. The cron daemon reads the cron tables of the users. These tables can be managed with the crontab command. The format is described in section 5 (type: man 5 crontab).

So you enter in a terminal window the command:
crontab -e
Then you enter the following lines:
Output:
#min hour monthday month weekday command 15 9,12,15 * * 1-5 /usr/bin/python3 /home/username/bin/script.py >>/home/username/output.txt 2>&1
Meaning:
Output:
15 : the minute of the hour when the command should run 9,12,15 : the hours on which the command should run * : the day of the month when the command should run (* = all) * : the monthin which the command should run (* = all) 1-5 : the day of the week the command should run (mon - fri) /usr/bin/python3 /home/username/bin/script.py >>/home/username/output.txt 2>&1 : the command.
to do in code, see sched