How to Set crontab for 4th and 25th of every month?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to Set crontab for 4th and 25th of every month?
# 1  
Old 04-01-2014
How to Set crontab for 4th and 25th of every month?

Hello,

I wanted to set Crontab for 4th and 25th of every month at 5:00 PM.

Script should take previous month and current year as command line arguement like...
Code:
/home/test1.sh -f ABCD 03 2014

so above script will run on 4th and 25th April 2014 but argument should be like previous month i.e 03.

Last edited by vbe; 04-01-2014 at 10:12 AM..
# 2  
Old 04-01-2014
You can use a list in the day-of-month field, like 4,25, so the crontab entry should look like 0 17 4,25 * * /home/test1.sh -f ABCD.
I'm afraid arguments can't be modified, so you need to calculate the values needed in the script itself.

EDIT:
Maybe you can use a wrapper script that calls your initial script with that calculated date?
# 3  
Old 04-01-2014
Thanks Rudi,

Cant we do `date '+%m'`-1 or somewhat like calculations or

or can you please give me the code for wrapper script or inside the script modification..
# 4  
Old 04-01-2014
You can put your date commands inside your script and they should work fine. If you are calling supplied/compiled code, you will need to write a script to call it with the correct parameters and get cron to schedule your script.



Robin
# 5  
Old 04-02-2014
Any other expert advice/ Suggestion to pass previous month to script .
Any big head in Shell scripting..

As its a AIX so `date -d -1month +%Y%m` this one is also not working..

how to write wrapper script...

Please help!
# 6  
Old 04-02-2014
IN AIX , I have also faced same problem for getting previous date .

I am using following codes .

Code:
year=`date +%Y`
m=`date +%m`
month=`expr "$m" - 1` 
if [ "$month" -le "10" ] ; then
pmonth=0`echo $month`
else
pmonth=`echo $month`
fi
if [ "$month" == "0" ] ;then
pmonth=12
year=`expr "$year" - 1`
fi
echo $year
echo $pmonth

This may be helpful to you .
# 7  
Old 04-02-2014
On AIX you should have the kornshell 93 installed as /bin/ksh. With this shell you can simplify the code to
Code:
printf "%(%Y %m)T" "1 month ago" | read year month
echo $year
echo $month

This User Gave Thanks to hergp For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

2. Shell Programming and Scripting

cron to get executed on 2nd and 4th saturday of every month

Hi , i need to reboot a server during 2nd and 4th saturday every month. i have come up with the below cron 30 17 8-14 * * if ; then /rebootscript; fi # to reboot every second saturday 30 17 22-28 * * if ; then /rebootscript; fi # to reboot every fourth saturday I am wondering why it... (3 Replies)
Discussion started by: chidori
3 Replies

3. 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

4. UNIX for Dummies Questions & Answers

How to Set up a cronjob On 4th Sunday of every Month?

How to Set up a cronjob which will run On 4th Sunday of every Month at 8:00 PM :( (11 Replies)
Discussion started by: tp2115
11 Replies

5. Solaris

crontab entry to run a script on 1st of every month.

What should be the crontab entry in solaris to run a script on 1st of every month? Is this correct? 00 02 1 * * <script to be executed> (5 Replies)
Discussion started by: deepaksahni0109
5 Replies

6. UNIX for Advanced & Expert Users

Crontab For First Monday Of Every Month!!

Hi, Could any one please let me know the crontab entry for scheduling a job for every first monday of the month? Thank You in advance, Sue (2 Replies)
Discussion started by: pyaranoid
2 Replies

7. Shell Programming and Scripting

crontab entry to run every last day of the month

i've created a script which should run every last day of the month. what would be the exact crontab entry for this? thanks! (9 Replies)
Discussion started by: tads98
9 Replies

8. 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

9. UNIX for Dummies Questions & Answers

CRONTAB: Every second Tuesday of the month

Morning everyone. You'll need to excuse me for I'm running a little empty this morning. Need to execute a job every second Tuesday of the month. Am I correct in my understanding that this isn't possible directly from crontab & hence I'll need to script. Does anyone have any similar solutions ?... (2 Replies)
Discussion started by: Cameron
2 Replies

10. UNIX for Dummies Questions & Answers

Crontab First Monday of Month only

Is there a way to setup a cronjob that will only run on the first monday of the month? (3 Replies)
Discussion started by: molonede
3 Replies
Login or Register to Ask a Question