Solved

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

Posted on 2004-10-29
427 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
Question by:starfield
    11 Comments
     
    LVL 10

    Expert Comment

    by:NetworkArchitek
    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:
    Please have a look at my script in:
    http:Q_20702441.html
    0
     
    LVL 38

    Expert Comment

    by:yuzh
    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
     
    LVL 12

    Expert Comment

    by:stefan73
    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
    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
    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
    right, which is pretty much what I suggested but less pseudo code. Ah well =)
    0
     
    LVL 51

    Expert Comment

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

    Expert Comment

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

    Author Comment

    by:starfield
    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
    please reread suggestions: they all tell you to rename *before" using ftp
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now