20.34 批量远程执行命令

批量远程执行命令

  • 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 "yes\r"}
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
  • exe.sh 内容
#!/bin/bash
for ip in `cat ip.list`
do
    echo $ip
    ./exe.expect $ip "w;free -m;ls /tmp"
done

猜你喜欢

转载自my.oschina.net/u/3707314/blog/1620674