0

For starters, I'm a total beginner when it comes to Linux/AWS/system stuff like this. At the moment, I have a nanny script (from an earlier question) that is running 24/7:

#!/bin/bash
while [ True ]
do
  python3 script.py
done

However, it's chewing up CPU time and starting to cost me more than it should. In reality, I dont need this script to run from:

10pm-3am EST Mon/Tues/Weds/Thurs/Fri

10pm EST Fri -> 3am Monday

Is there a simple way to setup some sort of scheduler for this nanny script, so that it shuts itself off during those above times? I've heard 'cron job' brought up before, but have no clue to set one up.

PS. Not sure this matters, but I use "screen" to run my nanny script, so that it doesnt quit as soon as I close out of the terminal connection.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
keynesiancross
  • 3,441
  • 15
  • 47
  • 87

1 Answers1

0

Cron is a scheduling utility in Linux. A command which you have scheduled with Cron is called a "Cron job". You can easily use Cron to start your program at 3 am on weekdays. You can also make another Cron job to shut it off at 10 pm on weekdays, but in reality it is probably better to do this from within your python program.

Use crontab -e to edit your Cron file, and add an entry specifying your scheduling pattern, the path to your Python executable, and the path to your python script. e.g.

0 3 * * 1,2,3,4,5 /usr/local/bin/python3 /<path to script.py>

This website might help you to better understand Cron time codes: https://crontab.guru/

  • Sorry for the delay getting back, was afk. thanks for the help, I'll try that today! The only thing about using python script to shut off, is that my nanny script is designed to force this flaky script to keep running (there are some deep seeded 3rd party connection issues that cause all sorts of havoc) – keynesiancross Aug 01 '22 at 16:50