0

I've got Ubuntu 14.04 I try to learn about using anacron. And there're 3 things so far that I can't understand. Please explain!

  1. WHEN is the anacron command (tast) executed for the FIRST TIME? Let's say today is Wednesday 2 p.m. (14:00) and I've just made a new weekly task for anacron. So when should I be expecting the first execution of it? In other words, what's the starting point here? Weekly, starting from...???

  2. Let's say I've got 3 commands. So this MUST be a script OR... I can stuff all three commands in ONE single anacron task? To be more specific, I want to stop the process, delete the file's content and then to re-start the same stopped process.

  3. Where should I put the commands for anacron? They say that in /etc/anacrontab, but there I see 3 default lines of commands that govern the cron (if I understand that correctly). Should I write my own commands in the same place just below those three?

1

The main thing to realise is that anacron is designed to complement cron; you should really just configure jobs in /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly. anacron is not designed for jobs that run more frequently; its main purpose is to allow daily, weekly or monthly jobs to "catch up" on computers which aren't on all the time.

  1. anacron uses timestamps and the time elapsed since the last execution to decide whether to run a job. If you declare a weekly job, i.e. one with a delay of seven days, anacron will run it whenever it detects that it hasn't been run for seven days. So when you create a new job, it should run it the next time it is invoked; by default this is either the next time the system is rebooted, the next time its power status changes (from battery to AC), or at 3am.

  2. Create a script with the three commands and drop it in /etc/cron.daily (or .weekly or .monthly, as appropriate).

  3. As indicated above, you should just use /etc/cron.{daily,weekly,monthly}. You can use /etc/anacrontab if you want but that's not the intended use.

See the Debian/Ubuntu-specific documentation and the anacron README for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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