Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm looking for a daemon that will run a command once every week. But I am not looking for something like cron that will run a command at a specific time. Because my laptop is turned off a lot, it happens a lot that that command will not run, because it simply misses the moment that cron runs that command.

Thus, I am looking for a daemon that I can tell to run a command whenever it has been a week (or any other amount of time) since it has ran that command.

I have been searching around a lot for such a utility, but I have not been able to find it. So, does anyone here know such a utility?

share|improve this question
Is anacron available on your platform? If it "misses" the last run it will run it next time the system starts. Of course that doesn't do the "every week" thing. If that's what you really need use a shell-script that runs what you need, and writes out a flag for it's last run, and checks on run how long ago that last run was. – tink Mar 17 '13 at 23:51
Anacron looks interesting, but as you said, it doesn't exactly do what I am looking. I was hoping that there was a daemon that would do exactly what I'm looking for. Thanks anyways! – kokx Mar 17 '13 at 23:59
I'm afraid your on your own; but as I said: I tiny shell wrapper, and anacron, will do the job just fine. – tink Mar 18 '13 at 0:07
up vote 2 down vote accepted

OK, so if you created a cron entry like this for the relevant user (your question wasn't very specific with the spec):

0/5 * * * * /path/to/script

and script looks something like this and you do chmod +x /path/to/script

set -x
today=$(date -d "today 00:00" "+%s")
if [[ -s ~/cronflag && -f  ~/cronflag ]]; then
  if [[ $(( $today - $(cat  ~/cronflag ) )) -ge 604800 ]]; then
    echo huzzah!
#    /path/to/weekly
    echo $today > ~/cronflag
    exit 0
#  /path/to/weekly
  echo hip-hop huzzah!
  echo $today > ~/cronflag
  exit 0

you should be able to get your desired result presuming that a) you add the thing you want done weekly in both spots where you see # /path/to/weekly (without the # ;}) and b) the machine usually gets an uptime of >= 10 minutes.

share|improve this answer

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.