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
# 1  
Old 12-07-2017
To run the script based on dates

I am having below script which needs to be executed based on start and end date
Code:
#!/bin/bash
array=('2016-09-27' '2016-10-27' '2016-11-27' '2016-12-27' '2017-01-27' '2017-02-27' '2017-03-27' '2017-04-27' '2017-05-27' '2017-06-27' '2017-07-27' '2017-08-27' '2017-09-27' )
for i in "${array[@]}"
do
echo "executing" $i

sh test.sh $i

if [ "$?" = "0" ]; then
echo "completed $i"
else
echo "failed"
#exit 1
fi

If i pass parameter as 2017-09-27 and 12, then the script should loop for last 12 months including 2017-09-27, Similarly if i give 6 then 6 months likewise any number

So far i have tried
Code:
#!/bin/bash
FROM_DATE=2016-09-27
TO_DATE=2017-09-27
FROM_DT=$FROM_DATE
while [[ $FROM_DATE < $TO_DATE ]]
do

echo "executing for $FROM_DT"

sh  test $FROM_DT

if [ "$?" = "0" ]; then
echo "completed $FROM_DT"
else
echo "failed"
#exit 1
fi
FROM_DATE=$(date -d "$FROM_DATE + 1 month" +"%Y-%m-%d")

done

# 2  
Old 12-07-2017
Not sure I understand. You seem to want to run a script for several selectable months back from a certain date.
Why do you define that 12 element array? Why the loop? Where do you pass the date parameter?

Did you search these fora for similar if not idential problems and solutions? I'm pretty sure that kind of problem has been solved umpteen times before.
# 3  
Old 12-07-2017
Actually Yes i will pass in my script the date and duration like say 12 or 6 or anything based on that it will loop the internal script 12 months by passing tha parameter

Code:
sh main_script.sh 2017-09-27 12

#this will loop like this

sh test.sh 2016-09-27
sh test.sh 2016-10-27

.
.
.
.

# 4  
Old 12-07-2017
But what is your problem? Eyeballing your script suggests to me that it should work the way you intend it to. Your original post boils down to "I want to do this and have written this script to do it". A statement and no questions.

Andrew
# 5  
Old 12-07-2017
Should your problem be that the date parameter to test.sh is not progressing, you might want to scrutinize sh test $FROM_DT and its development...
# 6  
Old 12-07-2017
Sorry for confusing guys. Actually as i said i am having a main script where date and number of months will be passed fo e.g..

Code:
sh main_script.sh 2017-12-10 12<YYYY-MM-DD>

Inside the main script i would be calling a subscript called test.sh which has date as input parameter. Based on my inputs from main_script parameter i need to run the internal script for 12 months back starting from 2016-12-10 till 2017-12-10 by passing each dates to test.sh

Code:
sh test.sh 2016-09-27
sh test.sh 2016-10-27

.
.
.
.

# 7  
Old 12-07-2017
What is that <YYYY-MM-DD>?
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 04:32 PM.

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