LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-23-2007, 01:14 PM   #1
telamonides
LQ Newbie
 
Registered: Feb 2007
Posts: 5

Rep: Reputation: 0
Question FTP script to multiple hosts


Hello,

I am trying to automate ftp to multiple hosts. I know how to write an ftp script for the ftp session, but I cannot seem to pass a variable to ftp or open for a consecutive list of hosts. Below is what I am working with:

for x in `cat list` # Where list is a file with all the host names I need to ftp to, eg. host1, host2, hostn...
do
echo $x
ftp -inv < script
done

That is simple enough. Here is my 'script'

open $x # This is where I seem to have a problem
user username password
bin
cd /dir/
put filename
bye

If I put in an actual hostname after open then it works for that host, but I do I pass a variable to this command so I can send a file out to a multitude of hosts? Thanks for your help.

telamonides
 
Old 02-23-2007, 01:41 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What happens if you use a .netrc for the credentials
and just go
ftp $x
?

Or, better yet, use ssh/scp and passwordless authentication ;}


Cheers,
Tink
 
Old 02-23-2007, 01:51 PM   #3
telamonides
LQ Newbie
 
Registered: Feb 2007
Posts: 5

Original Poster
Rep: Reputation: 0
ftp $x does not work (open is the same thing. The authentication is not the problem because if I actually put a single host in the $x spot it works. What I need to put this file on several hundred machines and want to ftp to a variable host. Thanks for the reply.

telamonides
 
Old 02-23-2007, 02:04 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I don't think it wouldn't be QUITE the same as open
because for the open you have already handed over control
to ftp .... Did you actually try it?

And as for the single host works: do your hosts come one
per line or all on one line?


Cheers,
Tink
 
Old 02-23-2007, 02:32 PM   #5
telamonides
LQ Newbie
 
Registered: Feb 2007
Posts: 5

Original Poster
Rep: Reputation: 0
If I do it ftp $x or open $x (open is an alias for ftp according to man and I have seen it in mulitple scripts) I get an ftp error that states: Name or service not known. According man ftp interprets a $ as a macro. I just want to know if it is possible to pass a variable to ftp in bash. It may not be, but it would be nice to know for sure so that I can look for some other method. Thanks.

telamonides
 
Old 02-23-2007, 03:12 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What distro are you using? I've never seen anyone refer to
open being an alias for ftp.

Quote:
According man ftp interprets a $ as a macro. I just want to know if it is possible to pass a variable to ftp in bash.
And this is where my suggestion comes in. If you use
ftp $variable the variable will be expanded BEFORE ftp
is run. And if you put the credentials and the commands
into your .netrc you're sweet.

The other approach would be to use expect instead, but
I think my suggestion is easier (and in this case probably
more elegant, too). What you need to understand is that
as soon as you pass control to the ftp process shell variables
aren't working any more.

Another approach would be to echo the whole sequence of your
commands to ftp, but again, I think that .netrc is more elegant.



Cheers,
Tink
 
Old 02-23-2007, 05:58 PM   #7
telamonides
LQ Newbie
 
Registered: Feb 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Smile

I figured out my problem. The file I was reading from with all the host names was copied from a windows box over to linux and apparently had all the character info in it causing ftp to try a non-existent hostname. I regenerated the file on linux and ftp $x works fine. Thanks for trying to help.


telamonides
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple addressing through hosts files Slick666 Linux - Networking 3 07-25-2006 09:10 AM
Deploying sudo to multiple hosts rohang Linux - General 1 12-13-2005 10:21 PM
PGP across multiple hosts mr666white Linux - Security 4 08-22-2004 10:14 AM
RH:8 Multiple Hosts Problem ecroswell Linux - Newbie 9 03-17-2003 05:53 AM
multiple virtual hosts iquadri1 Linux - Networking 1 09-25-2001 10:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration