![]() |
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 |
| Help, I need to get the last date of previous month | sirrtuan | Shell Programming and Scripting | 11 | 10-14-2008 06:59 AM |
| How to get the Previous month in Korn Shell | nvuradi | Shell Programming and Scripting | 1 | 03-19-2008 12:31 AM |
| Check File Exists and compare to previous day file script | rbknisely | Shell Programming and Scripting | 3 | 02-07-2008 11:53 AM |
| How to find the first day of previous month in unix? | mohapatra | Shell Programming and Scripting | 10 | 07-02-2007 09:57 PM |
| How to get previous month files | savitha | Shell Programming and Scripting | 7 | 03-23-2006 05:16 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
file name using previous month
This has probably been asked 100 times, but I couldn't find any articles on point. I have a script that runs on the last day of every month at 11:30pm. If cats a number of input tables that were created the previous month (or earlier), combines them into one master file and erases the indivual files. It also compresses any master files from previous months. My problem is that if the script is run on August 31, it will take all the files from July, and make a master file with the name EKVI0804.DAT
What I want to do is a have it use the previous month (EKVI0704.DAT) for the file (since the files belong to July). Below is my current script. Any help would be appreciated. ========================== #!/bin/ksh # Because a cron job can not be told to run on the last day of a month, # it will be run on the 28-31 of every month at 11:30pm. The following # code will determine if we are on the last day of the month. Because a # cron job doesn't have any environmental variables available from the # submitting session, all paths need to be hard coded. If this job needs # to be run for a gers production except live, please make the # approporate modifications to the path names. The test will be for any # file that was created before the current month. days_in_month=$(echo $(cal) | awk '{print $NF}') day_of_month=$(date +%d) if [[ $days_in_month -eq $day_of_month ]] then touch -m -t `date +%Y%m`010000.01 /gers/live/adhoc/ekvidatetestfile cd /gers/live/datafiles find . \( ! -name . -prune \) -name "EKVI*\.DAT" -type f ! -newer /gers/live/adhoc/ekvidatetestfile -exec compress {} \; cd /gers/live/adhoc find . \( ! -name . -prune \) -name "EKVI*" -type f ! -newer /gers/live/adhoc/ekvidatetestfile -exec cat {} > /gers/live/datafiles/EKVI`date +%m%y`.DAT \; find . \( ! -name . -prune \) -name "EKVI*" -type f ! -newer /gers/live/adhoc/ekvidatetestfile -exec rm {} \; rm /gers/live/adhoc/ekvidatetestfile else echo not the last day of the month exit fi |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|