Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 8222  / 2 Years ago, mon, january 24, 2022, 5:45:05

I wan to run a backup script once per day but I don't want to specify a certain time, just once per day. I've read that the @daily cron attribute runs every day at 00:00 but i don't know if the receiving server will be up at this time.



Is it possible to configure cron to run this script just once per day irrespective of the time? Or run the script until it succeeds and then try again the next day?



@reboot would be an option however the sending end might reboot several times per day in which case it would lead to unnecessary backups.


More From » cron

 Answers
4

You may want to use the anacron.



From its man page




NAME
anacron - runs commands periodically

SYNOPSIS
anacron [-s] [-f] [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job] ...
anacron [-S spooldir] -u [-t anacrontab] [job] ...
anacron [-V|-h]
anacron -T [-t anacrontab]

DESCRIPTION
Anacron can be used to execute commands periodically, with a frequency specified in days. Unlike
cron(8), it does not assume that the machine is running continuously. Hence, it can be used on
machines that aren't running 24 hours a day, to control daily, weekly, and monthly jobs that are usu‐
ally controlled by cron.



The Ubuntu community HowTo: https://help.ubuntu.com/community/CronHowto



Using anacron:




  1. Simply put the executable script file in the /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly.


  2. Touch the script file:



    sudo touch /etc/cron.daily/scriptfile


    (cron.daily if it is a daily job).




Testing anacron:



sudo anacron -f -d



   -f     Force execution of the jobs, ignoring the timestamps.
-d Don’t fork to the background. In this mode, Anacron will output
informational messages to standard error, as well as to syslog.
The output of jobs is mailed as usual.



Anacron messages in the log:



grep anacron /var/log/syslog


Anacron keeps timestamps in the /var/spool/anacron/. If you remove cron.daily, cron.weekly or cron.monthly files from there, anacron will execute daily, weekly or monthly scripts at the next startup.


[#41272] Tuesday, January 25, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
attagjump

Total Points: 272
Total Questions: 127
Total Answers: 124

Location: Taiwan
Member since Fri, Sep 17, 2021
3 Years ago
;