[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

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?
0
starfield
Asked:
starfield
  • 3
  • 2
  • 2
  • +3
1 Solution
 
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:
Please have a look at my script in:
http:Q_20702441.html
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now