scp.sh
#!/bin/sh
ip_list=/home/tools/scp/iplist
src_file=/home/probecheck.sh
dest_file=/home/
username=root
password=123456
cat $ip_list | while read line
do
host_ip=`echo $line | awk '{print $1}'`
echo "$host_ip"
./scp.exp $host_ip $username $password $src_file $dest_file
done
scp.exp
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_file [lindex $argv 4]
spawn scp $src_file $username@$host:$dest_file
expect {
"(yes/no)?"
{
send "yes
"
expect "*assword:" {send "$password
"}
}
"*assword:"
{
send "$password
"
}
}
expect "100%"
expect eof