Need help with incrementing date in while loop.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with incrementing date in while loop.
# 1  
Old 08-05-2008
Need help with incrementing date in while loop.

I need to execute a KornShell (SunOS 5.9) script against a range of dates:

endDate=20080804
extractDate=20080401
while [ $currentDate -le $endDate ]; do
batch < scripts/myshellscript.sh $extractDate
## add 1 day to extractDate ##
done

My question is how do I increment the extractDate variable and still have it give a valid date?
# 2  
Old 08-05-2008
For your example only - Aug 1 to Aug 4 2008 this will work. It will not work for crossing month-end boundaries.

Code:
endDate=20080804
extractDate=20080401
while [ $currentDate -le $endDate ]; do
   batch < scripts/myshellscript.sh $extractDate
   extractDate=$(( extractDate + 1 ))
done

# 3  
Old 08-05-2008
You can use convert current/past time in epoch time and do the calculation. Once got the result again convert it back to normal time and display it.

for more details about epoch time.
Unix time - Wikipedia, the free encyclopedia

- nilesh
# 4  
Old 08-05-2008
maybe with the "date" comand you can do the math
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date to Day in loop

Hi All, I have a file in the following format.I need to pick up 25th field which is a date and convert it into a day and add it as a field in the file. "AAGENAS,PEARL... (3 Replies)
Discussion started by: nua7
3 Replies

2. UNIX for Dummies Questions & Answers

Help with incrementing the date

I have a date variable like 2012-12-31 ( YYYY -MM -DD ) in flat file and it has to be incremtented by 1 every time i run the script Example : i tried the below script after data modifcation but this does not seem to work expr `20121231 +%Y%m%d` + 1 Note : Mine is not a GNU... (4 Replies)
Discussion started by: akshay01987
4 Replies

3. Shell Programming and Scripting

Incrementing the date depending on the Counter (parameter) passed to the script

Hello Everyone, I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server. i.e. Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4). First I will check for the... (1 Reply)
Discussion started by: filter
1 Replies

4. Shell Programming and Scripting

For loop with date

Hi I have 1 question regarding using date in shell script.Can we use for loop with date Req 1. I need to run the loop for certain date range 2. Check each date in loop that is Sunday or last day of month then exit 0 3. also if the date is 1 day before last day of month and also is Friday... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

5. Homework & Coursework Questions

Incrementing Variable resets outside of while loop

1. The problem statement, all variables and given/known data: Variable is resetting to 0 after incrementing in while loop My bit of scripting displays the current users logged in the machine. Then it reads in a specific username and displays the processes for that user. The portion that I... (3 Replies)
Discussion started by: ratzlaff
3 Replies

6. Shell Programming and Scripting

Incrementing in while loop

echo "Enter Starting id:" echo "" read rvst_strt_idxx echo "" echo "Enter Closing id:" echo "" read rvst_clsn_idxx FIELD1=$rvst_strt_idxx FIELD2="USER" FIELD3="TEST" FIELD4="12345" FIELD5="00000" echo "" echo "INSERT INTO TABLE( FIELD1, FIELD2, FIELD3, FIELD4, ... (7 Replies)
Discussion started by: ultimatix
7 Replies

7. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

8. Shell Programming and Scripting

Increment date in 'for' loop?

Hi Guys, My first post..:) Right...I want to move existing files (with some date in their name) currently in $mainftp, to $mainfolder/$foldate/system1. I'd like to be able to increment date in the for loop? Is this possible or should I use a different technique. The script return the... (4 Replies)
Discussion started by: SunnyK
4 Replies

9. Shell Programming and Scripting

New iteration of for-loop without incrementing?

Another question, is it possible to, in a for-loop incrementing until it reaches a certain number, to have it loop again without incrementing? Just have it drop what it is doing when it reaches this command and start again at the same number it was at? I know I could make a while loop and just... (0 Replies)
Discussion started by: jeriryan87
0 Replies

10. Shell Programming and Scripting

incrementing a for loop

I have, LIST="a b c d e" for word in $LIST do echo $word done would give me a b c d e With the first iteration of the for loop, I get "a" as the result. Is it possible that I get both "a" and "b" in only the first iteration. In the next iteration I get "c" and "d" and so on.... (2 Replies)
Discussion started by: run_time_error
2 Replies
Login or Register to Ask a Question