Unix/Linux Go Back    



To run the script based on dates

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member RudiC Regarding:
To run the script based on dates.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 12-07-2017   -   Original Discussion by rohit_shinez
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 25 May 2018, 6:41 PM EDT
Location: Aachen, Germany
Posts: 12,751
Thanks: 415
Thanked 3,921 Times in 3,605 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.