Operating System - HP-UX
1752691 Members
5634 Online
108789 Solutions
New Discussion юеВ

Re: run a script every two days ?

 
V. Nyga
Honored Contributor

Re: run a script every two days ?

Hi again,

if you don't like to read in a file, you also can check if a file exists.
So for example start with file 'file0.txt', if this file exists move it to 'file1.txt' and run your script. If it doesn't exist mv the file 'file1.txt' to 'file0.txt' and do nothing more.

(you also could write the current date to this file for 'problem detection' ...)

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Steven Schweda
Honored Contributor

Re: run a script every two days ?

> [...] i think following cron job will help

Well, at least it doesn't fail _every_ week.

> [...] who can give me a good method?

I suppose that only a few failures every year
might be "good", for some values of "good".

Sigh.
Dennis Handly
Acclaimed Contributor

Re: run a script every two days ?

As mentioned you schedule it for every day and you check inside your script.

Depending on how accurately you care about "every" two days, you can simply check on the julian day of the year.
if (( $(date +%j) % 2 == 0 )); then
exit
fi

If you need to be accurate for the next decade or so, you can get the previous year and test for a multiple of 4.
Chris shi
Frequent Advisor

Re: run a script every two days ?

Thank you for everybody's reply!
I think V. Nyga's method is a better way and Steven Schweda is a responsible man~
I will add the script then.
Dennis Handly
Acclaimed Contributor

Re: run a script every two days ?

>Volkmar: you also can check if a file exists.

Slight variation. If the file exists, remove it and exit.
If it doesn't, touch it and continue.
Steven Schweda
Honored Contributor

Re: run a script every two days ?

> Slight variation. If the file exists,
> remove it and exit.
> If it doesn't, touch it and continue.

As usual, many things are possible.

Of course, if a come-and-go file is
accidentally deleted, then you can't detect
its absence as a problem. Other schemes are
harder to fool. Everything's complicated.
(Or else it should be.)
Dennis Handly
Acclaimed Contributor

Re: run a script every two days ?

>Steven: if a come-and-go file is accidentally deleted, then you can't detect its absence as a problem.

This is failsafe. It then does it the next day. So it is a feature. :-)

I'm assuming that "every two" is fuzzy and we aren't printing duplicate checks. ;-)