Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
not sure if there is a nice crontab way of doing it, but you could have it run every 7 days and your script could just quit every other time instead of doing work
druuna, you have to escape the % signs in the crontab entry, otherwise they are interpreted as newline characters and all data after the first % are sent to the command as standard input. This is a special behavior of crontab.
According to the requirement the schedule date should not be date specific i.e. on14th and 28th for example. It should run after every 14 days. I have tried with the above command. But it won't work as per requirement
I guess I'm not sure I understand the requirements.
The command given is not date specific, it runs every 7 days (and checks if the week is odd/even to make it every 14 days), in this specific example it always runs on the first day of the week (1 = monday). Without looking at my agenda I don't have a clue what mondays date is or the one that is 14(+) days ahead. After the fact you could make a schedule and get the dates it runs on, and you will get a nice stat that shows dates, 14 days apart. It seems to me that is what you want/asked for.
In alternative you can try the at command, in place of crontab. To execute the same script after 14 days, try the following code at the end of your script:
Code:
at now + 14 days << EOF
$(readlink -f $0)
EOF
the command readlink -f $0 gives the full path of the script itself.
There is one possible downside to this: Even if the script runs for a short while (say minutes), this will create a sliding window; Every next occurence will run 14 days and a few minutes (maybe hours?) later then the previous one.
Maybe you should place that code snippet in the beginning of the script instead of the end. The same 'problem' is still in effect, but we are talking about a second or so, which should keep you safe for a long while.
Maybe you should place that code snippet in the beginning of the script instead of the end. The same 'problem' is still in effect, but we are talking about a second or so, which should keep you safe for a long while.
You're right, druuna! Thank you for the clarification.
Hi Senrooy,
I too need the same thing which you have done. can you please post the script which you have done to schedule a job in crontab to run every 14 days.
Thanks in advance
Ok, I know this is a really old question but I'm trying to better understand the workings of the evaluation being done. Maybe rehashing it a bit will prove of use to someone searching for information on how to accomplish this sort of aim.
Some tests reveal that the evaluation logic will work for cron jobs that are supposed to run in even-numbered weeks (as calculated from the start of the year), as stipulated in one of the answers given and as the following seems to reveal:
Code:
[ $(expr `date +%W` % 2) = 0 ] && echo yes
The word "yes" will appear after running this command if it is run during an even-numbered week.
If it is desired for the cron job to run in odd-numbered weeks, then
Code:
[ $(expr `date +%W` % 2) = 1 ] && echo yes
seems the right evaluation logic to use. Have I understood correctly how this works?
If so, a sample cron entry that should run some command every two weeks in odd-numbered weeks would look like this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.