Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 607  / 3 Years ago, fri, may 7, 2021, 12:03:12

Suppose I set up a cron job with anacron, or with crontab -e.



Now, what if my machine is switched off at the moment cron should have executed the scheduled job?



Would the job be executed as soon my machine is turned on?
Or would it not be executed at all?


More From » cron

 Answers
0

If you are using cron, then the job will Not be executed if the computer is off at that time.



If you are using anacron for that job, it will be executed once the computer is turned On next time. The time of execution needs some explnation. Note that the smallest unit of time from anacron is day, so you can only set an anacron job that will have a frequency to run of 1 day or more.



Here is a sample entry of /etc/anacrontab:



1       5       cron.daily      run-parts --report /etc/cron.daily



  • The initial 1 indicates that this job will run each day (frequency=1 day)


  • 5 indicates that there will be 5 minutes delay after the start of the computer before running this job


  • cron.daily is the job identifier for anacron, it is used to identify specific jobs in the spool directory /var/spool/anacron/


  • run-parts --report /etc/cron.daily is the command to be executed.




So, if your computer was turned off at the time of running the job, anacron will check the timestamp of last run from /var/spool/anacron/cron.daily. If it was executed the previous day or earlier then anacron will run the job and update the timestamp accordingly.



Ubuntu uses anacron for daily, weekly and monthly jobs. From /etc/crontab:



05 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )


As you can see everyday at 6:05 AM, the daily jobs will be run from /etc/cron.daily. If anacron exists, it will parse /etc/anacrontab (and run run-parts to execute the files under /etc/cron.daily), otherwise cron will use run-parts to directly execute all files under /etc/cron.daily.



If the computer is Off at that time, anacron will run the job after turning it On next time as per instructions from the /etc/anacrontab file.


[#19796] Friday, May 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deringach

Total Points: 412
Total Questions: 107
Total Answers: 101

Location: Palestine
Member since Tue, Jul 20, 2021
3 Years ago
;