0

I am fairly new to ubuntu/linux and python so I beg forgiveness in advance. I have a small python script that I typically start in a terminal screen. This script runs a simple task then sets a timer to run the same task again in 4 hours. I want to run this in the background and I also want it to start running when the server boots. I am sure this question has been asked before, but I have not had much luck finding the solution. Any help would be greatly appreciated. Basic cod below.

import os
import datetime
from threading import Timer

x = datetime.datetime.today()

if x.hour+4 > 23
    do some stuff
else
    do other stuff

Function()
    Repeat above stuff

t = Timer(sec, Function)
t.start()

1 Answers1

0

For anyone that needs to know, as it was mentioned in the comments I edited the crontab file. I actually only needed it daily, so it was very simple.

crontab -e

On the last line I added:

0 1 * * * python /file_location/file.py

This runs file.py at 1:00 AM.

(minutes) (Hour) (day of month) (day of week) command
Melebius
  • 11,431
  • 9
  • 52
  • 78