Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
google site



IP Networking Learn TCP/IP, Internet Protocol, Routing, Routers, Network protocols in this UNIX and Linux forum.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-29-2001
Registered User
 

Join Date: Aug 2001
Location: CA
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Question Automated FTP task

Every day i ftp tar.gz a file from the production server to a back up machine.. This task creates way to much traffic on the network at the end of the day and puts and undo load on the production machine during operation hours. i would like to create a script that would automatically fire off the ftp at like 2:00 am so that the transfer occurs when there is little or no load on the network. if anyone has suggestions on how to accomplish this, PLEASE let me know...

thanks..

--e0

loworderbit@aol.com
Sponsored Links
  #2  
Old 08-29-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
auto-ftp transfers

You can set up a ".netrc" file for the
user doing the transfer then set up a cron
job for that userid to run a script to actually
do the FTP transfer.
Check the man pages for ftp(1) and netrc(5)
  #3  
Old 08-29-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
Thanks: 0
Thanked 8 Times in 8 Posts
I need to do a lot of automated ftp jobs myself. I have tried several versions of this and have finally settled on a style of script that I like. I found that using a .netrc file to automate the logging-in process kept painting me into a corner because different scripts needed to sign in as different users. So I avoid .netrc and force the script to sign in. I don't like to allocate pty's unless I really am forced into it, so I also avoid pty based tools like expect. I really like ksh so that was my tool of choice. And I like the co-process concept because it makes feeding commands into the ftp process so easy with "print -p". The only problem is that the co-process manipulates standard-out so as to make it available to "read -p". And it's too hard to know how many "read -p" I will need. So I send the output to a different file descriptor. Putting it all together:


Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz
print -p bye

wait
exit 0

That script will tranfer the file and the output of the script will be the output from the ftp job itself. Put the script into cron and save the output so you can look at it the next morning.

Last edited by Perderabo; 07-02-2004 at 08:44 AM..
  #4  
Old 08-29-2001
ober5861's Avatar
Registered User
 

Join Date: Jul 2001
Location: Gettysburg, PA
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
hmm... write a script on the server that is launched daily using the cron (man crontab)... have that script ftp to your workstation or wherever and grab the file. The automated FTP will probably require a .netrc file in your user directory or wherever you ftp to to get the file.

However, if you are having to tar the file manually every day, write a script on the workstation side to do that for you a few minutes before the server script executes... once again, utilizing the crontab.

Good luck and let me know how it goes.

Strange... those other replies both popped up while I was writing... ummm... take their advice.

Last edited by ober5861; 08-29-2001 at 02:40 PM..
  #5  
Old 08-29-2001
ober5861's Avatar
Registered User
 

Join Date: Jul 2001
Location: Gettysburg, PA
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
exec 4>&1
ftp -nv >&4 2>&4 |&
Perderabo... can you explain what that does exactly?

  #6  
Old 08-29-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
Thanks: 0
Thanked 8 Times in 8 Posts
Quote:
Originally posted by ober5861


Perderabo... can you explain what that does exactly?

That is the file descriptor manipulation. Recall that fd 0 is standard-in, fd 1 is standard-out, and fd 2 is standard-error. The line "exec 4&>1" opens fd 4 and assigns it to whatever fd 1 was assigned to. As you will see, I am sorta "saving a copy of fd 1 in fd 4".

The line "ftp -nv >&4 2>&1 |&" is a little harder.

The "|&" turns the process into a co-process that allows subsequent "print -p" statements to send lines to the co-process' standard-in and "read -p" to read from its standard-out. So ksh forks a copy of itself and fiddles with the fd's 0 and 1 until this it set-up. But it leaves the rest of the fd's alone.

Then it encounters ">&4" which causes it to set the ftp process' standard out to whatever 4 is. Well since 4 is a copy of 1 before the co-process, we are back to writing to the original shell's standard out. Lastly, the 2>&4 does the same thing for standard error. I could've used "2>&1" at this point for the same effect.

This is hard to explain, but I hope this helps.

  #7  
Old 08-29-2001
Registered User
 

Join Date: Aug 2001
Location: CA
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Ftp

thanks for all of the help.. i guess i should have mentioned that i am running sco openserver.. i dont know if it matters or not, but the more information the better.... anyway, it looks like the best way to do this is to set up a script and use crontab..
manually, i was using the get command from the back up machine, but if its all the same, put from the production machine will work fine.
now, its time to get down to the creation of the script and setting up cron to run it...
my unix background is about three weeks, but i have been an (i apologize in advanced) NT admin for over a year, so please forgive my ignorance.
anyway, if any of you would like to assist me in setting this up i would be very gratefull... This website, Unix: the complete reference, and sco unix in a nutshell are the only resources i have so far, so i am relying on you all a little...

thanks again...

e0--
Sponsored Links
Closed Thread

Bookmarks

Tags
linux, mtime, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
automated ftp. sangfroid Shell Programming and Scripting 10 05-07-2007 11:52 AM
process vs task hana UNIX for Dummies Questions & Answers 2 07-02-2006 06:32 PM
Automated FTP shauche UNIX for Advanced & Expert Users 11 07-11-2002 02:08 AM
FTP automated? n9ninchd UNIX for Dummies Questions & Answers 6 05-18-2001 10:21 AM



All times are GMT -4. The time now is 07:57 AM.