Home Man
Search
Today's Posts
Register

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

Tags
date -d, shell scripts, solved

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 12-07-2017
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
# 9  
Old 12-07-2017
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.
# 10  
Old 12-08-2017
Thanks,

it worked for me

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

« Previous Thread | Next Thread »
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
Call script parameter based on dates Master_Mind Shell Programming and Scripting 4 05-15-2018 09:36 AM
Delete files older than 1week(dates need to be calculate based on file name) Agoyals1986 Red Hat 2 06-23-2017 11:00 AM
Script with Dates michipoput Shell Programming and Scripting 3 07-12-2016 08:11 PM
awk - printing new lines based of 2 dates Ads89 Shell Programming and Scripting 10 03-24-2016 01:37 PM
Separate output based on dates Jimmy_the_tulip Shell Programming and Scripting 5 09-25-2014 08:32 PM
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
script to Find the files based on dates it came krux_rap Shell Programming and Scripting 2 12-10-2010 07:54 PM
How to processing the log file within certain dates based on the file name shyork2001 Shell Programming and Scripting 1 04-09-2010 10:58 AM
Need script to generate all the dates in DDMMYY format between 2 dates frozensmilz Shell Programming and Scripting 2 01-29-2009 05:06 AM
To get previous or future dates based on input value Sharmila_P Shell Programming and Scripting 5 08-08-2008 07:54 AM


All times are GMT -4. The time now is 01:20 AM.

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