Python Forum
Py script that triggers ever 3 hours, but only between 9:15 am to 3:30 pm, Mon to Fri
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Py script that triggers ever 3 hours, but only between 9:15 am to 3:30 pm, Mon to Fri
#1
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.
Reply
#2
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.
Reply
#3
to do in code, see sched
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  MatplotibTicks every 24 hours TamP 4 1,104 Oct-04-2022, 04:08 PM
Last Post: deanhystad
  Hello all! need help. calculating OT hours. no1up 5 1,428 Jul-30-2022, 10:00 PM
Last Post: rob101
  How to get utcnow + 2 hours? korenron 2 2,492 Mar-01-2021, 03:22 PM
Last Post: korenron
  Need to add hours min and seconds tester_V 5 3,029 Jun-02-2020, 05:29 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020