标签:localhost 不同 log exit .sh host index div txt
该脚本实现对不同主机批量执行命令
[root@localhost ~]# cat 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"
[root@localhost ~]# cat exe.sh
#!/bin/bash for ip in `cat ip.txt` do echo $ip ./exe.expect $ip ‘w ; free -m ; ls /tmp" done
[root@localhost ~]# cat ip.txt 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4
[root@localhost ~]# chmod a+x exe.expect [root@localhost ~]# chmod a+x exe.sh [root@localhost ~]# sh exe.sh
标签:localhost 不同 log exit .sh host index div txt
原文地址:http://www.cnblogs.com/pzk7788/p/7198543.html