- 论坛徽章:
- 0
|
我觉像这样100 台机器 用 expect 完全可以解决....
shell:
#! /usr/bin/expect -f
for {set i 2} {$i< 101} {incr i} {
set ip 192.168.0.$i
set pwd xxxx
spawn ssh $ip
expect {
"*continue connecting (yes/no)?*"
{
send "yes\r"
exp_continue
}
"*assword*"
{
send "$pwd\r"
exp_continue
}
"*permisson*"
{
send_user "ip error!\n"
}
"*Last login*"
{
send "./xxx.sh\r"
exp_continue
}
}
}
输出不怎么好看..... 而且是串行的.....
下面写了个很挫的python脚本(因为是多线程的 个人认为比较好):
#! /usr/bin/python
import paramiko
import pexpect
import threading
def myssh(user,ip,password):
cmd=“./xxx.sh”
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip,username=user,password=password)
except:
print "connect to %s failed!!" %ip
else:
i,o,e=ssh.exec_command(cmd)
print o.read()
for i in range(2,101):
ip ="192.168.0." + str(i)
th=threading.Thread(target=myssh,args=("root",ip,"password"))
th.start()
仅供参考(新手初写,高手包涵)........ |
|