LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   run a cron every second day (https://www.linuxquestions.org/questions/linux-newbie-8/run-a-cron-every-second-day-944198/)

apss_evaluator 05-10-2012 04:40 AM

run a cron every second day
 
Hi guy's

I've been searching a procedure on how can I run a command every 11:59 midnight every in every 2nd day interval. sample today is monday it will run on 11:59 pm and the run will be tuesday of 11:59 pm.


I've been looking for samples in google but I havent found any. just hourly, daily, weekly and monthly schedules.


Thanks in advance

Satyaveer Arya 05-10-2012 04:45 AM

Quote:

sample today is monday it will run on 11:59 pm and the run will be tuesday of 11:59 pm.
It means that you want to run the command everyday at 11:59 PM.

Here is an example site for you - cronjob exmpales.
Now you can try with the help of those examples by understing cron and cronjob.

Steviepower 05-10-2012 07:43 AM

maybe run it every 48 hour? see http://www.adminschoice.com/crontab-quick-reference
and I'm just assuming you mean monday and wednesday?

Steviepower 05-10-2012 07:44 AM

I also found this: http://www.absolutewillynilly.com/we...ob-run-2-days/

Babertje 05-10-2012 02:03 PM

There is also a trick to let the cronjob store the unix time in seconds after a completed job in a timestamp log file just let it run each day and If the difference is less than 172000 seconds you let it skip the job not updating the timestamp file. And If it is greater than 172000 you let it run and overwrite the timestamp log with a new one

Kustom42 05-10-2012 02:15 PM

Why not just:

Code:

  .---------------- minute (0 - 59)
#  |  .------------- hour (0 - 23)
#  |  |  .---------- day of month (1 - 31)
#  |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
#  |  |  |  |  .----- day of week (0 - 7) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
#  |  |  |  |  |
#  *  *  *  *  *  command to be executed
  *  *  */2 *  *  /your/command/here.sh


Babertje 05-10-2012 06:22 PM

With a timestamp based script it doesn't care if you restarted the machine.
Added an example script for desktop usage for running a backup job each 48 hours even if you don't use the computer for 3 days it will take action on that thirth day. This script just needs to be called by cron.daily
skip_a_day.cron.sh.tar.gz

Steviepower 05-11-2012 02:21 AM

with the every second day */2 option in crontab it shouldn't be hard to do either

rknichols 05-11-2012 10:54 AM

Quote:

Originally Posted by Steviepower (Post 4675701)
with the every second day */2 option in crontab it shouldn't be hard to do either

That's if you don't mind a little glitch in the sequence following each month that has an odd number of days.


All times are GMT -5. The time now is 08:19 PM.