Chinaunix

标题: FTP脚本求助 [打印本页]

作者: sea987    时间: 2013-08-27 00:16
标题: FTP脚本求助
大家好,情景:solaris终端机FTP到某一个网段10多台solaris服务器上的相同目录抓取2个文件,且每个服务器的这两个文件名相同;需求:在终端机上自动建立这10多台服务器Hostname的文件夹,且将各自服务器文件ftp到对应的目录。请大家提供下思路,有现成脚本更好。谢谢大家!
作者: rdcwayx    时间: 2013-08-27 06:45
本帖最后由 rdcwayx 于 2013-08-27 08:45 编辑
  1. HOST='ftp.users.net'
  2. USER='yourid'
  3. PASSWD='yourpw'
  4. FILE='file.txt'

  5. for HOST in server1 server2 serverx ....
  6. do
  7.   #FTP
  8. ftp $HOST <<END_SCRIPT
  9. user $USER
  10. $PASSWD
  11. put $FILE
  12. quit
  13. END_SCRIPT

  14. done
复制代码

作者: donalds2008    时间: 2013-08-27 11:28
#!/bin/bash

usr="xx";#user
pwd="xx";#password
get_file="xx";#file
ip_file="ip.list"#server ip list

expect <<EOF
set timeout 3
set list_ip [open $ip_file r]
while {[gets \$list_ip ip ] != -1} {
exec mkdir \$ip
spawn ftp \$ip
expect "Name"
send "$usr\r"
expect "*ssword"
send "$pwd\r"
expect "ftp>"
send "cd dir\r"
expect "ftp>"
send "get $get_file \$ip/$get_file \r"
expect "ftp>"
send "quit\r"
}
expect eof
EOF
作者: donalds2008    时间: 2013-08-27 11:28
  1. #!/bin/bash

  2. usr="xx";#user
  3. pwd="xx";#password
  4. get_file="xx";#file
  5. ip_file="ip.list"#server ip list

  6. expect <<EOF
  7. set timeout 3
  8. set list_ip [open $ip_file r]
  9. while {[gets \$list_ip ip ] != -1} {
  10. exec mkdir \$ip
  11. spawn ftp \$ip
  12. expect "Name"
  13. send "$usr\r"
  14. expect "*ssword"
  15. send "$pwd\r"
  16. expect "ftp>"
  17. send "cd dir\r"
  18. expect "ftp>"
  19. send "get $get_file \$ip/$get_file \r"
  20. expect "ftp>"
  21. send "quit\r"
  22. }
  23. expect eof
  24. EOF
复制代码

作者: 秋天的絮儿    时间: 2013-08-27 15:55
  1. ftp -niv <<END
  2. open HOST
  3. user xxx xxxx
  4. binary y
  5. lcd /xxxx
  6. put xxx.txt
  7. close
  8. END
  9. ftp -niv <<END
  10. open HOST
  11. user xxx xxxx
  12. binary y
  13. lcd /xxxx
  14. put xxx.txt
  15. close
  16. END

  17. ...........................
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2