20.34 批量远程执行命令

2022-01-06 14:11:55 浏览数 (2)

批量远程执行命令

  • exe.expect 内容
代码语言:javascript复制
#!/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 内容
代码语言:javascript复制
#!/bin/bash
for ip in `cat ip.list`
do
    echo $ip
    ./exe.expect $ip "w;free -m;ls /tmp"
done

0 人点赞