Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-10-2012, 04:40 AM
|
#1
|
Member
Registered: Mar 2012
Posts: 115
Rep: 
|
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
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
05-10-2012, 04:45 AM
|
#2
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
|
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.
|
|
|
05-10-2012, 07:44 AM
|
#4
|
Member
Registered: May 2010
Location: Eindhoven
Distribution: ubuntu/debian
Posts: 152
Rep:
|
|
|
|
05-10-2012, 02:03 PM
|
#5
|
Member
Registered: Jun 2009
Location: Haarlem, The Netherlands
Distribution: Archlinux
Posts: 125
Rep:
|
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
|
|
|
05-10-2012, 02:15 PM
|
#6
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
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
|
|
2 members found this post helpful.
|
05-10-2012, 06:22 PM
|
#7
|
Member
Registered: Jun 2009
Location: Haarlem, The Netherlands
Distribution: Archlinux
Posts: 125
Rep:
|
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
Last edited by Babertje; 05-11-2012 at 04:48 AM.
|
|
|
05-11-2012, 02:21 AM
|
#8
|
Member
Registered: May 2010
Location: Eindhoven
Distribution: ubuntu/debian
Posts: 152
Rep:
|
with the every second day */2 option in crontab it shouldn't be hard to do either
|
|
|
05-11-2012, 10:54 AM
|
#9
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,815
|
Quote:
Originally Posted by Steviepower
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.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 07:22 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|