starfield
asked on
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?
#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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ssh + rsync
scp
sftp
ssh + tar
to do the backup.
you can also use "wget", see http:Q_21057930.html
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
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
ASKER
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.
cp /live_directory/abrtest /process_directory/arbtest -`date '+%Y%m%d'`
# then proceed with your expect script, probably without your file1 part
# then proceed with your expect script, probably without your file1 part
right, which is pretty much what I suggested but less pseudo code. Ah well =)
hmm, agreed
I'm used to stop reading at second or third line, usually;-)
I'm used to stop reading at second or third line, usually;-)
Your script does no error checking as such.
There will be unsolvable problems all the tame
There will be unsolvable problems all the tame
ASKER
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.
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.
please reread suggestions: they all tell you to rename *before" using ftp
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!