1834686 Members
1798 Online
110069 Solutions
New Discussion

Re: Cron job

 
SOLVED
Go to solution
Reuben Ernest
Occasional Advisor

Cron job

Hi,
I am not an expert in UX, just migrated from. So, the question i am putting up might be stupid, but please bear with me.

Q)* * 1-7 * 6 job

Would this run on the 1st saturday of the month or would it run on first 7 days as well as on all saturdays?

Thanks for you patience!
Ben
11 REPLIES 11
Emiel van Grinsven
Valued Contributor

Re: Cron job

Hi,

This is the syntax

minute hour monthday month weekday command

not sure what overrides the other.
of course, there's no harm in testing is there??

Grt, Emiel
Deepak Extross
Honored Contributor

Re: Cron job

Reuben,

From the man page of crontab:
...
Note that the
specification of days can be made in two fields: monthday and weekday
If both are specified in an entry, they are cumulative. For example,
0 0 1,15 * 1 command
runs command at midnight on the first and fifteenth of each month, as
well as every Monday.
...

Hope this clarifies it!

Cheers,
Deepak.
Emiel van Grinsven
Valued Contributor

Re: Cron job

take a look at this,

Note that the
specification of days can be made in two fields: monthday and weekday.
If both are specified in an entry, they are cumulative. For example,

0 0 1,15 * 1 command

runs command at midnight on the first and fifteenth of each month, as
well as every Monday.

hope it answers your problem,

grt, Emiel
K.Vijayaragavan.
Respected Contributor

Re: Cron job

For the entry " * * 1-7 * 6 job " in crontab,
It will run on first 7 days as well as on all saturdays.

-Vijay

"Let us fine tune our knowledge together"
Deepak Extross
Honored Contributor

Re: Cron job

Incidentally, * * 1-7 * 6 job means that you want the job to run EVERY MINUTE OF EVERY HOUR on the 1st to 7th of each month and on every Saturday.

Just pointing this out, because its not everyday that one sees a '*' in the Minute and Hour field.
John Carr_2
Honored Contributor

Re: Cron job

Hi

I think 1-7 means on each day and if you had 1,7 it would mean day 1 and day 7.


Your job will run the first even days of the month and each saturday

checkout man cron

John
Michael Tully
Honored Contributor

Re: Cron job

Hi,

I think it will run as you've suspected.

What I would it to work out the particular
date relevant through a script, before
proceeding to run the jobs.

Personally I would use something like the
information provided from the following
thread. I've utilised it on a number of
occassions and it really works well.
Our collegue Mr Stephenson has done a wonderful
job with this.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xe752d20fd34bd61190010090279cd0f9,00.html
Anyone for a Mutiny ?
Reuben Ernest
Occasional Advisor

Re: Cron job

Thanks all for the response....now i need to figure out how to write a script that runs on 1 saturday of everymonth

Ben
Deepak Extross
Honored Contributor
Solution

Re: Cron job

Ben,

You could try this:
Define your job to run on every Saturday like so:
0 0 * * 6 job

Then, in your job, add the following:
#!/usr/bin/ksh
if [ $(date +%d) -lt 8 ]
then

fi

HTH.
Reuben Ernest
Occasional Advisor

Re: Cron job

Deepak,
That was simple and to the point. Now i wonder why i didnt think of it in the first place :(

Thanks a lot
Ben
John Carr_2
Honored Contributor

Re: Cron job

Reuben

0 0 * * 6 job

#!/usr/bin/ksh
if [ $(date +%d) -lt 8 ]
then

fi

is this really what you want, using this method "job" will only run once on the first Saturday of the month as subsequent saturdays the test will say date days is greater than 7 and not do anything.

If you only want the job to run on the first saturday use cron

* * * 6 * job

John.