(1) First, save the host IP you want to transfer to a file
VI IP 10.161.4.x 10.161.4.x 10.161.4.x |
(2) scripting
#!/usr/bin/ksh
Username=tomcat # Here is the user name for connecting to the remote host, as in this case the remote host user names connected
#echo $username
Password= ' xxxxx ' # here is the password
#echo $password
Homedir= ">"
ip_form= ' [email protected] ' #这里要与username变量的值一样, we are tomcat here, so this is [email protected]
For IP in $ (cat IP)
Do
mingling= "SCP /home/tomcat/copy/mon_con.sh $ip _form$ip:/home/tomcat" #这里要注意文件的; Path
#echo $mingling
/usr/local/bin/expect-c "
Set timeout 5;
Spawn $mingling
Expect {
\ "(yes\/no) \" {Send \ "Yes\r\"}
}
Expect {
\ "*assword*\" {send \ "$password \r\"}
}
# expect "* $homedir *"
#send \ "$mingling 6\r\"
Expect "* $homedir *"
Send \ "Exit\r\"
Expect EOF; "
Done
(3) If you want to verify the results of the execution, you can output this script to a file, and then retrieve the file.
This article is from the "good_job" blog, make sure to keep this source http://gogoing.blog.51cto.com/9763598/1692249
Linux System Bulk Transfer file (SCP)