How to run cron when the system is offline
Cron will skip the execution if the server is not online at the time that they are scheduled. This is default behavior and its not possible to run cron when the system is offline.
But Linux provides another utility called anacron which execute commands periodically with a frequency specified in days. If the machine if off when a scheduled job is due, it will execute a scheduled job when the machine is powered on the next time.
Anacron jobs can be configured in the file "/etc/anacrontab".
#vi /etc/anacrontab
The job syntax should be as follows.
period delay job-identifier command
Where,
period – this is the frequency of job execution specified in days or as @daily, @weekly, or @monthly for once per day, week, or month. You can as well use numbers: 1 – daily, 7 – weekly, 30 – monthly and N – number of days.
delay – it’s the number of minutes to wait before executing a job.
job-id – it’s the distinctive name for the job written in log files.
The following is an example for anacron job configured to run daily.
@daily 10 backup /bin/bash /root/backup.sh
That's all…