FTP from one unix server to another and add date extension to file

I have a problem where I'm backing up a file by using ftp to transfer from one unix server to another. This is going to be done every night so when the file is moved I need the date extension to be added to the file so that it doesn't overwrite the previous nights backup. So far I have:


#copy from live to processing directory then compress
cp /live_directory/abrtest /process_directory/
compress process_directory/abrtest



expect_version -exit 5.24.1
set file [lindex $argv 0]
set file1 "000001"
set timeout 1200

#create a new ftp session and put the file on the test server

spawn ftp xxx.x.x.xx
expect "Name*:"
send "name\r"
expect "Password:"
send "pass\r"
expect "ftp>"
send "cd /test_directory\r"
expect "ftp>"
send "put "abr$file\r"
expect "ftp>"
send "bye\r"
close

It's at the stage above that I'd like to somehow add a date extension when the "put "abr$file\r" command is used. Can anyone help me with this problem?
starfieldAsked:
Who is Participating?
 
yuzhCommented:
Please have a look at my script in:
http:Q_20702441.html
0
 
NetworkArchitekCommented:
Hi starfield,
you can do something like that

stamp = `date +"filename"`;

copy file stamp

ftp ...
put stamp...
rm stamp ...

Well, its just a skeleton, I think you can flesh that out, maybe. Hope it helps.

Cheers!
0
 
yuzhCommented:
FTP is not secure, consider setup secure shell in your box and use
ssh + rsync
scp
sftp
ssh + tar

to do the backup.

you can also use "wget", see http:Q_21057930.html
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
stefan73Commented:
Hi yuzh,
Good point. Having your password sitting around as clear text in a script is a potential security problem. scp is definitely the better choice.

Cheers!

Stefan
0
 
starfieldAuthor Commented:
Thanks for the advice but thats not really what I was asking. I have pretty basic knowlege of shell scripting so the simplest script is what I'm after at this stage.
0
 
ahoffmannCommented:
cp /live_directory/abrtest /process_directory/arbtest-`date '+%Y%m%d'`
# then proceed with your expect script, probably without your file1 part
0
 
NetworkArchitekCommented:
right, which is pretty much what I suggested but less pseudo code. Ah well =)
0
 
ahoffmannCommented:
hmm, agreed
 I'm used to stop reading at second or third line, usually;-)
0
 
gheistCommented:
Your script does no error checking as such.
There will be unsolvable problems all the tame
0
 
starfieldAuthor Commented:
Thanks for the help. It's actually at the ftp part that i've having trouble renaming the file. At the line

send "put "abr$file\r"

I don't know how to rename the file there with the date extension it gives me an error saying too many arguments.
0
 
ahoffmannCommented:
please reread suggestions: they all tell you to rename *before" using ftp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.