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 |
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 |
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 |
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 |
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 |
What distro are you using? I've never seen anyone refer to
open being an alias for ftp. Quote:
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 |
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 |
All times are GMT -5. The time now is 08:33 AM. |