Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Script to obtain a file with "yesterdays" timestamp??

Status
Not open for further replies.

gringomike

Technical User
Aug 6, 2003
148
GB
Hi all,

I need a script to FTP a log file that was created "yesterday". These log files update throughout the day and as soon as midnight passes a new file is created with a new the current date integrated into the file name.

A directory listing returns the following;

access_log.Mar052005.log.Z
access_log.Mar062005.log.Z
access_log.Mar072005.log.Z
access_log.Mar082005.log.Z
access_log.Mar092005.log


Here's what I have so far;

DATE2=`/usr/bin/date +%b%d%Y`

for arg in "access_log.$DATE2.log"
do
DATE=`/usr/bin/date +%d%m%y`
PROFILE=abc
FILE=$arg
NEWFILE=$PROFILE.$DATE
echo "\
open 123.48.75.124
user username password
lcd /log_area
cd /a/b/c
bin
get $FILE
quit
" | ftp -n -i -v
done
cd /nettracker_logs
echo "Renaming log file from $FILE to $NEWFILE"
mv $FILE $NEWFILE
echo "File successfully renamed"
echo "Transfer Complete"

This would work if I ran the script at 23:59 however the only time I have permission to run this script is at 3am. As a result, it only picks up 3 hours worth of data (midnight until 3am)!!

All I have to do is have the script pick up yesterdays file (rather than todays) and unzip it once it has been transfered across.

I'm sure there's an easy way to do this but I can't find the answer using the date command and everything I've tried so far has been unsuccessful.

Help!
 
Write a shirt script to write the 'day before' date to a file in the format above (can be run anytime in the day concerned) and assign that to a variable in your script, so that it's looking at the correct file without having to worry about the date command itself.
 
Great - thanks Ken!

Sometimes the most obvious solutions need to be pointed out!

Thanks again!

GM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top