批量远程执行命令
- exe.expect 内容
#!/usr/bin/expect
set host [lindex $argv 0]
set passwd "123456"
set cm [lindex $argv 1]
spawn ssh root@$host
expect {
"yes/no" { send "yesr"}
"password:" { send "$passwdr" }
}
expect "]*"
send "$cmr"
expect "]*"
send "exitr"
- exe.sh 内容
#!/bin/bash
for ip in `cat ip.list`
do
echo $ip
./exe.expect $ip "w;free -m;ls /tmp"
done