which expect
vim do1.sh
for i in `cat iplist`
do
/usr/bin/expect <<EOF
spawn ssh -o StrictHostKeyChecking=no $i "命令" #我们可以用id命令来试验
expect "*password:"
send "密码\r"
send "exit\r"
expect eof
EOF
done
-------------------------------------------------------------------------
vim do2.sh
for i in `cat iplist`
do
/usr/bin/expect <<EOF
spawn scp -o StrictHostKeyChecking=no 本地目录/文件 $i:目录
expect "*password:"
send "密码\r"
send "exit\r"
expect eof
EOF
done
-------------------------------------------------------------------------
vim do3.sh
for i in `cat iplist`
do
/usr/bin/expect <<EOF
spawn ssh -o StrictHostKeyChecking=no "sudo /bin/sh - <<EOF
具体命令:比如hostaname
EOF"
expect "*password:"
send "密码\r"
send "exit\r"
expect eof
EOF
done