The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 08-04-2004
beilstwh beilstwh is offline
Registered User
  
 

Join Date: Jul 2004
Location: New York State
Posts: 65
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0