Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wan to run a backup script once per day but i dont 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.

Thanks a lot

share|improve this question
up vote 11 down vote accepted

You may want to use the anacron.

From its man page

       anacron - runs commands periodically

       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]

       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:

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.

share|improve this answer
So just dumping the scripts in the cron.daily will do the job? – ECII Dec 27 '11 at 16:51
Wha do you need to touch the script? – ECII Jan 4 '12 at 6:55
Sometimes, at here, the anacron is not executing the new script. The touch has helped at here. – user26687 Jan 5 '12 at 14:23

Use @daily as you are, but add @reboot as well. @reboot will run the script when you boot.

@reboot /full_path/to/script

See Ubuntu wiki cron for additional information.

share|improve this answer
Yes but this was I might get multiple executions per day, right? – ECII Dec 27 '11 at 16:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.