list.txt
192.168.1.1:root:passwd
192.168.1.2:root:passwd
…
192.168.1.50:root:passwd
cat/root/list.txt |
whileread row;do
IP=$(echo $row |cut -d : -f 1 )
username=$(echo $row |cut -d : -f 2 )
passwd=$(echo $row |cut -d : -f 3 )
pr='sysctl –w –q net.ipv4.tcp_tw_reuse = 1'
/usr/bin/expect -f /root/abc.sh"$IP" "$username" "$passwd" "$pr"
done
expect.sh
#!/usr/bin/expect -f
setip [lindex $argv 0]
setusername [lindex $argv 1]
setpassword [lindex $argv 2]
settimeout 10
spawn ssh$username@$ip
expect {
"*yes/no"{ send "yes\r"; exp_continue}
"*password:"{ send "$password\r" }
}
expect"#*"
send"[lindex $argv 3]\r"
send "exit\r"
expecteof