![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script To increment Date*HElp*** | niceboykunal123 | Shell Programming and Scripting | 1 | 04-23-2008 01:05 AM |
| how can i read a line using the 'for' | vadharah | Shell Programming and Scripting | 10 | 03-02-2008 02:26 PM |
| the given code goes in infinite loop and does not increment variable i | mrityunjay22 | Shell Programming and Scripting | 6 | 12-26-2007 02:20 AM |
| Using 'for' with 2 variables? | micro420 | Shell Programming and Scripting | 4 | 05-19-2007 05:02 AM |
| Date increment in the format "YYYYMMDD" | ganapati | Shell Programming and Scripting | 4 | 08-02-2006 11:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 following error ./movediselogs.sh: line 8: ((: foldate=070820: value too great for base (error token is "070820") Hope that makes sense... ----------------------- #!/bin/sh startdate=`/bin/date --date="10 weeks ago" +%y%m%d` currentdate=`/bin/date +%y%m%d` mainfolder=/data/backup mainftp=/ftp/upload/ftpsystem1 for ((foldate=$startdate; $foldate < $currentdate; foldate++)) do mkdir $mainfolder/$foldate/system1 mv $mainftp/*$foldate* $mainfolder/$foldate/system1 done ----------------------- Many Thanks SunnyK |
|
||||
|
Quote:
Thanks for replying... The solution you suggested should help me accomplish my task until date reaches the value 070831. However, after that, I'd like the script to increment the month (as in performing increment on a date variable) and perform the remaining part of the task until currentdate. I think this shouldnt be much of a problem in other programming languages (I am new to shell scripting though). Also, if you feel there is a better alternate approach, please feel free to suggest. Thanks SunnyK |
|
|||||
|
Lets the date command increment the date for you :
Code:
#!/bin/sh startdate=`/bin/date --date="10 weeks ago" +%y%m%d` currentdate=`/bin/date +%y%m%d` mainfolder=/data/backup mainftp=/ftp/upload/ftpsystem1 foldate="$startdate" until [ "$foldate" == "$currentdate" ] do mkdir $mainfolder/$foldate/system1 mv $mainftp/*$foldate* $mainfolder/$foldate/system1 foldate=`/bin/date --date="$foldate 1 day" +%y%m%d` done |
|
||||
|
Quote:
You're a star! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|