Unix/Linux Go Back    


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

Shell Programming and Scripting


Tags
date -d, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 6 Days Ago   -   Original Discussion by rohit_shinez
rohit_shinez's Unix or Linux Image
rohit_shinez rohit_shinez is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 8 December 2017, 2:18 AM EST
Posts: 192
Thanks: 59
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; 6 Days Ago at 09:22 AM.. Reason: Added CODE & ICODE tags
Sponsored Links
    #9  
Old Unix and Linux 6 Days Ago   -   Original Discussion by rohit_shinez
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 13 December 2017, 4:17 PM EST
Location: Aachen, Germany
Posts: 11,797
Thanks: 339
Thanked 3,659 Times in 3,357 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 Unix and Linux 5 Days Ago   -   Original Discussion by rohit_shinez
rohit_shinez's Unix or Linux Image
rohit_shinez rohit_shinez is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 8 December 2017, 2:18 AM EST
Posts: 192
Thanks: 59
Thanked 0 Times in 0 Posts
Thanks,

it worked for me

Last edited by rohit_shinez; 5 Days Ago at 03:18 AM.. Reason: thanks
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 12:46 PM
To run a script based on the value in text file nani1984 Shell Programming and Scripting 7 12-29-2010 09:37 PM
script to Find the files based on dates it came krux_rap Shell Programming and Scripting 2 12-10-2010 08:54 PM
Run a script based on the subject line of the email satekn Shell Programming and Scripting 5 04-16-2009 01:11 PM
trigger a script based on the run status of another scipt Athena Shell Programming and Scripting 1 10-02-2008 03:11 PM



All times are GMT -4. The time now is 10:34 PM.