Cron to schedule 1st Wednesday of every Month??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron to schedule 1st Wednesday of every Month??
# 1  
Old 10-20-2004
Cron to schedule 1st Wednesday of every Month??

Is there a way to use cron to run a job on the 1st Wednesday of every month?? The more generic question is, "Are all of the fields in crontab AND'd together or are some OR'd?".

i.e. I had an entry in my crontab this morning as follows and I didn't expect it to run since the day of month is 20 today, but it did run...

#Minute 0-59
# Hour 0-23
# Day of Month 1-31
# Month 1-12
# Weekday 0-6 Sun-Sat
#
22 09 8-14 * 3 /easdwld/audit/dev/bin/purge.audit
# 2  
Old 10-20-2004
As stated in the man page, specification of days may be made by two fields (day of the month and day of the week). Both are adhered to if specified as a list of elements. So you putting Wednesday as being able to run lets it run every Wednesday. You would have to add some logic to your script to get out of that (if date is higher than some number, exit).

Also, you state you want it to run on the first Wednesday yet you have 8-14. Seems to me that would be the second Wednesday of the month.

Some OS's may have different ways of changing this and allow what you are trying - read your man page or post your OS and version.
# 3  
Old 10-20-2004
Following on from RTM's reply.... running your commands via a script would work

try putting something like this in "call_me_from_cron"

Code:
#!/bin/bash

DATE=`date +%d`

if [ "$DATE" -le "7" ]; then
  run my commands
fi

exit


then in the crontab:

22 09 * * 3 /path/to/call_me_from_cron

To run the script at 09:22 on the first wednesday of each month.

Cheers
ZB
# 4  
Old 10-20-2004
try this

22 09 * 1-12 3 /easdwld/audit/dev/bin/purge.audit
# 5  
Old 10-20-2004
22 09 * 1-12 3 /easdwld/audit/dev/bin/purge.audit

That won't work - that'll run every wednesday. The OP wants the first wednesday of each month.

Cheers
ZB
# 6  
Old 10-20-2004
Thanks to all for the replies.

We're running AIX 5.1

I had initially coded the "day between 8-14" logic in my script but then thought it would be simpler to make it all happen with cron. But, as I see now, the dayofmonth and weekday are essentially OR'd.

I'll uncomment my date logic in the script and go forward as before.

Thanks again to all!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Schedule a shell script without crontab every Wednesday at 10 AM

HI Guys I need one shell script to be scheduled to run one shell script to be executed automatically every Wednesday at 10 AM Without crontab and "at" command.. Could you provide your suggestions ? Thanks and Regards kshitij Kulshreshtha (6 Replies)
Discussion started by: kshitij
6 Replies

2. HP-UX

Help with cron schedule

Hope you can help with a queuy i have. Server OS is HP-UX my cron runs like this: * * * * * /test/scripts/1_min_jobs.sh 1>/dev/null 2>/dev/null 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /test/scripts/jobs_5mins.sh 1>/dev/null 2>/dev/null 0,15,30,45 * * * *... (10 Replies)
Discussion started by: davexxash
10 Replies

3. Shell Programming and Scripting

schedule a job without Cron

Hi All, Is there any way (any utility) to schedule a job to run once in a week on RedHat Linux ? Note- Do not using Crontab. Thanks Pravin (1 Reply)
Discussion started by: pravin27
1 Replies

4. UNIX for Dummies Questions & Answers

Schedule a cron job

Hi, Can anyone help me out with scheduling a cron job for the below: i wnated to delete file from a folder on every sunday at 05:00 AM this is code i have used. ******************************************************* 0 05 * * 0 find /abc/xyz/pqrs/bak/ -type f -mtime +30 -exec rm -f... (5 Replies)
Discussion started by: ch33ry
5 Replies

5. Shell Programming and Scripting

crontab: setup cronjob to run first wednesday of every month

Hi, How to setup cronjob to run first wednesday of every month. Is there a way? Thanks.. (9 Replies)
Discussion started by: Anjan1
9 Replies

6. Shell Programming and Scripting

Schedule a Cron job

Hi all, I am new to cron jobs.. i wanted to schedule a cron job that wil send a mail to me at 3:00PM on 10th August ie is on Wednesday. 0 15 10 8 3 echo "message from UNIX here"|mail -s "your subject here" user@user.com However this was not executed... Can anyone please... (0 Replies)
Discussion started by: ch33ry
0 Replies

7. Shell Programming and Scripting

Schedule without cron

Hi, How to write the recursive function. I have a script, #!/usr/bin/ksh ## name=$1 outputfile='output.log' sqlplus -s > ${outputfile} <<__END__ ${USER}/${PASS}@${DB} WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK WHENEVER OSERROR EXIT FAILURE ROLLBACK SET ECHO ON SET SERVEROUTPUT... (3 Replies)
Discussion started by: sandy1028
3 Replies

8. Solaris

Prstat Cron Schedule

Hi , I am trying to set up a cron job for getting the prstats for every 10 minutes to a log file. prstat -s cpu -n 20 > a.txt The issue is when i try to execute this command, a.txt is filling up with data for every second which is not i wanted.I just need top 20 processes for every 10... (2 Replies)
Discussion started by: pyaranoid
2 Replies

9. UNIX for Dummies Questions & Answers

crontab schedule - first thursday of every month

Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once... (2 Replies)
Discussion started by: paulds
2 Replies

10. UNIX for Dummies Questions & Answers

schedule many jobs using cron

HI, I need to schedule a no.of jobs using the cron facility. I currently do two kinds of scheduling,one based on the database load(after the database is loaded the program will start) and the other is based on time.....(say 10.00a.m daily) the problem is.......... When the database is loaded... (1 Reply)
Discussion started by: sireesha15
1 Replies
Login or Register to Ask a Question