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 a file with date appended to filename.

Status
Not open for further replies.

Condore

Programmer
Aug 29, 2006
3
US
I'm sure this has come up before but I am not having much luck searching.

In order to FTP a log file on a daily basis from a Solaris machine and ensure that each file received has a modified name with the current day's date, I'm guessing I would neet to write a small script that pulls the current date and then call an FTP script which then sends the file in a NAMEmmddyy format - I'm thinking using the "date '%m%d%y'" to get the date and then appending that to the end of the filename during transmission.

How would you all recommend going about doing this?
Thanks in advance! (I hope this is in the more appropriate forum)
 
We have a similar script to that you require (amended to protect the innocent, but hopfully still readable):

Code:
mv /path/to/file/filename /path/to/destination 2> /dev/null
mv /path/to/file/ERROR_FILE /path/to/destination 2> /dev/null
cd /path/to/destination
if [ -f filename ]
then
export TEMP_NAME=filename_`date +%d%m%y"_"%H%M%S`
export ERR_FILE=ERROR_FILE_`date +%d%m%y"_"%H%M%S`
mv filename $TEMP_NAME
mv ERROR_FILE $ERR_FILE
ftp -i servername <<EOF
cd "directory"
put $TEMP_NAME
bye
EOF
/usr/bin/gzip $TEMP_NAME
else
echo "No file to process." > ERROR_FILE
export ERR_FILE=ERROR_FILE_`date +%d%m%y"_"%H%M%S`
mv ERROR_FILE $ERR_FILE
fi

Hopefully this will give you some ideas.

All I ask of you
Is make my wildest dreams come true
 
Thank you very much! This has pointed me in the right direction for sure.

Oh, and hello tek-tips forums, awesome site!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top