Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

#!/bin/bash
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
  fi
else
#  /path/to/weekly
  echo hip-hop huzzah!
  echo $today > ~/cronflag
  exit 0
fi

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

 
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.