Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to use anacron to run a job annually. I see only daily, weekly, and monthly configuration for anacron. Is there a way to run a job once per year?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Ofcourse and it is already there with the possible selections you have: pick 1 specific day and 1 specific month and it will run once per year. Day 1 of month 1 would be on the 1st of January.

Anacron has 2 ways of defining lines. The 2nd one is like this:

 @period_name delay job-identify command

The period_name can be set to daily, weekly, monthly, yearly or annualy. This will ensure jobs are run once a week, month or year no matter the number of days in this period.

Example

@yearly 0 job1 /usr/bin/execute_me

The 0 means no delay. job1 is an identifier and the command to execute.

share|improve this answer
2  
How would @period_name work with anacron? I thought it was used in crontab, which doesn't guarantee execution if the machine is off. –  Jeremy Stein Nov 25 '12 at 18:23
    
    
Ah, so could I add a line to anacrontab like this: @yearly 20 cron.yearly nice run-parts --report /etc/cron.yearly and then add my scripts to /etc/cron.yearly? –  Jeremy Stein Nov 25 '12 at 18:28
    
Do not know for sure but that last part (nice run-parts --report /etc/cron.yearly) probably needs to be 1 command (not that that is a problem since you can toss that in a script and execute the script). –  Rinzwind Nov 25 '12 at 18:33
add comment

I think this would work unless my computer was off for all of January:

File in /etc/cron.monthly:

#!/bin/sh
month=`date +%m`
if [ $month -eq 1 ]
then do_yearly_task
fi
share|improve this answer
add comment

Your Answer

 
discard

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.