Run shell script alternate week per month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run shell script alternate week per month
# 1  
Old 03-22-2013
Run shell script alternate week per month

Hi All,

Requirement :-
I have shell script in kern shell ,have to run alternate week per month
example-today's date is 27 Mar 2013 and my script will run today then for the next time when it will run it should check 1st what was the last run date(27 Mar 2013) if it is matched 15days from current date then run else sent a mail with waning mgs.

i have a AWK command it is checking only within a month
Code:
date +%Y:%m:%d|awk -vFS=":" -vOFS=":" '{$3=$3-3;print}'

suppose i am checking 20days from current date it is give some negative value
ex-2013:03:-8

Please give some advice me so i can move forward.

Thank you All.

Regards,
Krupa

Last edited by vbe; 03-22-2013 at 07:12 AM..
# 2  
Old 03-22-2013
RedHat use epoch arithmetic

you can perform epoch arithmetic

Code:
1 day = 86400 secs
15 days = 1296000 secs


today's date
Code:
$ date
Fri Mar 22 06:18:17 EDT 2013

script to calculate date after 15 days

Code:
today=`date +%s`;let after_15=today+1296000; date -d "@${after_15}"

o/p
Code:
Sat Apr  6 06:16:39 EDT 2013

This User Gave Thanks to sam05121988 For This Post:
# 3  
Old 03-26-2013
Hi,

I am getting below errors

Code:
`date +%s`;let after_15=today+1296000; date -d "@${after_15}"
date: bad format character - s
ksh: after_15=today+1296000: bad number
date: illegal option -- d
Usage: date [-u] [+format]
       date [-u] [mmddhhmm[[cc]yy]]
       date [-a [-]sss.fff]

this is Working in Bash shell but not in ksh
Please provide me alternate solutions

Thanks,
Krupa

Last edited by Franklin52; 03-26-2013 at 06:40 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run script on every last sunday of the month

Hi ALL, I have been testing this script to run for every last Sunday of the month,looks like month which have 5 sunday (july 2016 )is not passing this and failing every time. Here is what I am using, current_date=31 echo " CURRENT DAY -> $current_date" if ... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. Shell Programming and Scripting

Script to run on 2 4 and 7 day of the month

I am looking for a unix script which could run a job on 2, 4 and 7 working day of the month. if the days are falling on the saturday/sunday. it should run on the next day. Thank you.. (9 Replies)
Discussion started by: tradingspecial
9 Replies

3. Shell Programming and Scripting

Alternate mondays to run the script

I need to run a script every other monday (alternate mondays) , Can anyone has logic to put into timer script. We are using below logic to run scripts every day daywk_is=$(date "+%u") if ] then 1=monday, 2=tuesday, 3=wed, 4=thr, 5=fri, 6=sat, 7=sun can anyone have idea on this (14 Replies)
Discussion started by: nani1984
14 Replies

4. Answers to Frequently Asked Questions

Finding the nth Particular Week in a Month – shell script

I see lot of request posted in internet to find out the day of nth week in a Month. example: what is the date of 3rd Sunday in October What is the date of 2nd Friday in June 2012 what is the date of 4th Saturday in January 2011..etc.. The below shell script is used to find out the... (1 Reply)
Discussion started by: itkamaraj
1 Replies

5. Shell Programming and Scripting

run the script on every 31st of month.....

Hello expert, I need a logic code {don't want to schedule into crontab} which can run some of my code on 31st of Jan, March, Mya, Aug, Oct, Dec..... Ex: if then echo "success" fi Please help me in achieving this Thanks (3 Replies)
Discussion started by: aks_1902
3 Replies

6. Shell Programming and Scripting

run the script for last day of the month

Hello Experts, I have a script which i want to run the on last day of every month. let say I have backup.sh script which i want to run it every month last day. Can anyone please help :confused: thanks (4 Replies)
Discussion started by: aks_1902
4 Replies

7. UNIX for Advanced & Expert Users

How to scedule a script to be run on every second saturday in Month?

Hello Friends, In my project I have to schedule a script to be run on every second saturday (once in month). Can you please suggest what entry should I make in cron ? (5 Replies)
Discussion started by: sourabhsharma
5 Replies

8. UNIX for Advanced & Expert Users

Run a script parallel for a month's worth:

Is there a utility that can be used in a shell script that would run a .sql file for 30 or 31 days in a month at the same time parallely. Please Advice. Thanks SD12. (2 Replies)
Discussion started by: sd12
2 Replies

9. Shell Programming and Scripting

Execute a script on 4 week of the month

I need help to write a script and it will execute on Saturday of the last week of every month. For example : 09/30/2006 is the last Saturday on Sept. 2006 08/26/2006 is the last Saturday on Aug. 2006 07/29/2006 is the last Saturday on July. 2006 etc.. ... (1 Reply)
Discussion started by: tbdo88
1 Replies

10. Shell Programming and Scripting

Getting week in month.???

Hi All, I have a tricky problem. I need to write a shell script (bash) which identifies which week off the month it is. I need to create a partition each week. So for the first week (where first of the week is Monday) of March i want to create partition_march_01 and for the second partition... (1 Reply)
Discussion started by: Zak
1 Replies
Login or Register to Ask a Question