Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

To run the script based on dates


👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #8  
Old 12-07-2017
rohit_shinez rohit_shinez is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 11 June 2018, 12:52 AM EDT
Posts: 196
Thanks: 60
Thanked 0 Times in 0 Posts
Oh thats i was referring to which format the dates are being passed basically YYYY-MM-DD

Code:
sh main_script.sh 2017-12-10 12


Last edited by rbatte1; 12-07-2017 at 08:22 AM.. Reason: Added CODE & ICODE tags
Sponsored Links
    #9  
Old 12-07-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 July 2018, 3:40 AM EDT
Location: Aachen, Germany
Posts: 13,080
Thanks: 450
Thanked 4,017 Times in 3,693 Posts
How about
Code:
FDT=$(date -d "$1 - 12 month" +"%Y-%m-%d")
for MP in $(seq 0 $2); do date -d "$FDT + $MP month" +"%Y-%m-%d"; done
2016-12-10
2017-01-10
2017-02-10
2017-03-10
2017-04-10
2017-05-10
2017-06-10
2017-07-10
2017-08-10
2017-09-10
2017-10-10
2017-11-10
2017-12-10

Be aware that this yields 13 iterations, for 12 months back and the current month.
Sponsored Links
    #10  
Old 12-08-2017
rohit_shinez rohit_shinez is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 11 June 2018, 12:52 AM EDT
Posts: 196
Thanks: 60
Thanked 0 Times in 0 Posts
Thanks,

it worked for me

Last edited by rohit_shinez; 12-08-2017 at 02:18 AM.. Reason: thanks
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to read a log file and run 2nd script if the dates match SarwalR Shell Programming and Scripting 1 09-18-2012 11:46 AM
To run a script based on the value in text file nani1984 Shell Programming and Scripting 7 12-29-2010 08:37 PM
script to Find the files based on dates it came krux_rap Shell Programming and Scripting 2 12-10-2010 07:54 PM
Run a script based on the subject line of the email satekn Shell Programming and Scripting 5 04-16-2009 12:11 PM
trigger a script based on the run status of another scipt Athena Shell Programming and Scripting 1 10-02-2008 02:11 PM



All times are GMT -4. The time now is 06:52 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?