[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-10-29
11
Medium Priority
?
474 Views
Last Modified: 2010-08-05
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
Comment
Question by:starfield
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 12442272
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
 
LVL 38

Accepted Solution

by:
yuzh earned 500 total points
ID: 12442275
Please have a look at my script in:
http:Q_20702441.html
0
 
LVL 38

Expert Comment

by:yuzh
ID: 12442314
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:stefan73
ID: 12442727
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
 

Author Comment

by:starfield
ID: 12442886
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12451727
cp /live_directory/abrtest /process_directory/arbtest-`date '+%Y%m%d'`
# then proceed with your expect script, probably without your file1 part
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 12453263
right, which is pretty much what I suggested but less pseudo code. Ah well =)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12453552
hmm, agreed
 I'm used to stop reading at second or third line, usually;-)
0
 
LVL 62

Expert Comment

by:gheist
ID: 12455826
Your script does no error checking as such.
There will be unsolvable problems all the tame
0
 

Author Comment

by:starfield
ID: 12456563
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12458075
please reread suggestions: they all tell you to rename *before" using ftp
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question