3

I have a python script, and I wish to run it once and only once everyday. I did some research on the crontab command, and it seems to do so, but at a fixed time each day. The issue is that my computer won't be on all day and a specific time for running it is just not possible. What can I do?

Could a log file help? I was thinking of doing a crontab every 5 minutes or so and scanning a log file to see any runs for the day.

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
martianwars
  • 6,380
  • 5
  • 35
  • 44

4 Answers4

7

Install anacron, a cron scheduler that'll handle tasks that run at most once a day when your computer is powered on.

From the WikiPedia page:

anacron is a computer program that performs periodic command scheduling which is traditionally done by cron, but without assuming that the system is running continuously. Thus, it can be used to control the execution of daily, weekly, and monthly jobs (or anything with a period of n days) on systems that don't run 24 hours a day.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

Anacron will do it

or

at

Anacron is probably your best choice.

mikeb
  • 10,578
  • 7
  • 62
  • 120
0

@reboot can be used in crontab entry to run script once when system is rebooted.

e.g.

[test@host1 ~]$crontab -l    
@reboot     /home/test/bootScript.sh
Shubhangi
  • 2,229
  • 2
  • 14
  • 14
0

You can run it in a server which is on all day and everyday. You can get a free server hosting on sites like this: https://www.5gbfree.com/

This way, if you have sick days where you won't even think to open your laptop, the cron jobis still running in the server anyway.

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108