To run the script based on dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To run the script based on dates
# 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 or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Call script parameter based on dates

Hi Guys, I am having a script which needs to be iterated based on date passed and itrate based on no of months given. #!/bin/bash var_d=$1 months=$2 sh invoke_script var_d i need to iterate the inside script something like below sh invoke_script 170101 sh invoke_script... (4 Replies)
Discussion started by: Master_Mind
4 Replies

3. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

4. Shell Programming and Scripting

Need to check links exists in the server based on that need to run the build script

Hi, I am working on a build script which will check for the links existing in the server ,then run the gen command to start the build process. Appreciate help on this. server os:sun solaris 10.Bash shell links present in the server location /spa/5.0: genver -> sa0_genver_release... (1 Reply)
Discussion started by: muraliinfy04
1 Replies

5. Shell Programming and Scripting

To run a script based on the value in text file

I have a Text file as shown below /* text file begins---------- ----------- Monthly files Loaded ------------- input_file record_count load_count reject_count ------------ ----------- ----------- ----------- 1_IN.txt 221935 221935 0 2_IN.txt 270668 270668 0 3_IN.TXT 231666 80370 151296... (7 Replies)
Discussion started by: nani1984
7 Replies

6. Shell Programming and Scripting

script to Find the files based on dates it came

I need a script to get the files for DEC the file format will be B20_abc_ancdfefg_20101209_INCR_201012100145.TXT.gz Based on the bold ones (date) i need to get the files can any one help me plzzzzzz (2 Replies)
Discussion started by: krux_rap
2 Replies

7. Shell Programming and Scripting

Shell script to find the run time based on log entries?

Shell script to find the run time based on log entries? Below is the log files content updated when the script test.sh runs. I would like to calculte the difference between first update time stamp and last update time stamp to find the run time of the script. The below log file shows the first... (1 Reply)
Discussion started by: mailtopranesh
1 Replies

8. Shell Programming and Scripting

Run a script based on the subject line of the email

Hi, I need help in running a script that would pull info from an email subject line and run a script (foo.sh). I'm pretty sure after a bit of googling that this is possible in several ways. but none was pretty clear on how to accomplish it. The part that I really need help with is getting the... (5 Replies)
Discussion started by: satekn
5 Replies

9. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

trigger a script based on the run status of another scipt

Im a newbee.. I have a script which runs few times daily. I want to write another script which should pick up the latest log generated from the last run of the first job and trigger a thrid script if the first script runs successfuly. Please help... Cheers (1 Reply)
Discussion started by: Athena
1 Replies
Login or Register to Ask a Question