Operating System - HP-UX
1753293 Members
6230 Online
108792 Solutions
New Discussion юеВ

Re: run a script every two days ?

 
Chris shi
Frequent Advisor

run a script every two days ?

hello everybody,
I want to run a script every two days,who can give me a good methodя╝Я
Thank you very much!!!
16 REPLIES 16
V. Nyga
Honored Contributor

Re: run a script every two days ?

Hi,

you can define a cron job for every day.
In your script you can check a text file, start with '0', if it's '0' start the script and change the value to '1'.
If it's '1' change to '0' and exit your script without running.

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Vibhor Kumar Agarwal
Esteemed Contributor

Re: run a script every two days ?

In the day field use "*/2"

This will run your cron every alternate day
Vibhor Kumar Agarwal
Michal Kapalka (mikap)
Honored Contributor

Re: run a script every two days ?

Hi,

create cron job,

this link describe which values is possible to use to become your schedule.

http://www.adminschoice.com/docs/crontab.htm

mikap
Sunny123_1
Esteemed Contributor

Re: run a script every two days ?

Hi

you can set in cronjob

In cronjob set weekdays as 1,3,5,7

means if you want to run script name job in every 2 days at 1:00 am then following will be the line you have to edit in cronjobs using crontab -e

00 1 * * 1,3,5,7 /home/job

Regards
Sunny
Suraj K Sankari
Honored Contributor

Re: run a script every two days ?

Hi,
As everyone said the simple and best solution is set your job into crontab!!

Total 6 field's are there in crontab file
min hour day month dayofweek command
* * * * * *
Example
# Trim log files 1st. and 16th. Of every month at 11 PM.
0 23 1,16 * * /trimlog

for more info about crontab
see man pages

Suraj
Steven Schweda
Honored Contributor

Re: run a script every two days ?

> In the day field use "*/2"

Is that in the "monthday" field or the
"weekday" field? I don't see this notation
in the HP-UX "man crontab" page:

http://docs.hp.com/en/B2355-60130/crontab.1.html

Please help me find it.

> In cronjob set weekdays as 1,3,5,7

You mean "crontab"? In the field described
as:

weekday
The day of the week, 0-6, 0=Sunday

where "7" seems to be conspicuously absent?

How many people believe that there is an
even number of days in a week? (Or a month,
every month? Or a year, every year?)

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

Not so many people as you might have thought,
apparently.

> In your script you can check [...]

Probably not as reliable as a cron-only
scheme, but at least it can count. You could
store the day-of-year in the file, too, and
have the script check for any missed days, if
that sort of problem detection would be
useful.
Sunny123_1
Esteemed Contributor

Re: run a script every two days ?

Hi

You are right steven i think following cron job will help

0 1 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /home/job

Regards
Sunny
James R. Ferguson
Acclaimed Contributor

Re: run a script every two days ?

Hi:

I think Volkmar has the most appropriate solution --- use a file into which you write either a "0" or a "1" every time your script executes. If on startup the file contains "0"; overwrite it with "1" and exit. If on startup the file contains "1" overwrite itwith "0" and continue your execution cycle.

There is no "/' notation in HP-UX's implementation of cron. This is a GNU/Linux offering.

Specifying a series of days in your crontab entry (e.g. 1,3,5 ... 29,31) doesn't work well since months contain a variable number of days (let alone compensating for leap years).

Regards!

...JRF...
V. Nyga
Honored Contributor

Re: run a script every two days ?

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

>Not so many people as you might have thought, apparently.

lol - thanks Steven

@Sunny - this will also not work, after the 31st the 1st follows, so no day between.

V.
*** Say 'Thanks' with Kudos ***