0

I ran into trouble with cron. I need to run task on my desktop but the thing is I can't guarantee that my computer will be turned on in specified time.

For example I need to execute task weakly

If I specify

* * * * 6 user my_very_useful_task

my_very_useful_task will be executed every minute on Sunday but I need only once

If I specify

0 9 * * 6 user my_very_useful_task

my_very_useful_task will be executed in 9:00 AM, but I can't guarantee that computer will be turned on in this time

1 Answer 1

1

Use anacron. From the man anacron page:

  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 usually controlled by cron.

You can find a concise introduction here. At any rate, modify the /etc/anacrontab file as follows: create a line with this format

 period   delay   job-identifier   command

Period is how often you want the job to run, acceptable values are 1 (daily), 7 (weekly), N (= every N days); delay is the time in minutes after boot the job has to wait before being executed; job-identifier is a file in the directory /var/spool/anacron where a record of the last execution of the command will be kept. Lastly command is the command you want to execute.

An example of a line in /etc/anacron is

  1 10 test.daily /home/my_name/bin/my_command

This will execute the command /home/my_name/bin/my_command daily (the option 1), leaving a record of its execution in /var/spool/anacron/test.daily, and, if at the time of the execution the pc is odwn, it will wait for 10 minutes after the next boot up to execute the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .