[root@localhost ~]# cat test_nothread.py
import paramiko
import threading
import os
def ssh2(ip,username,passwd,cmd):
file_path='/root/perror.log'
logfile=file(file_path,'a')
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,username,passwd,timeout=5)
for m in cmd:
stdin, stdout, stderr = ssh.exec_command(m)
# stdin.write("Y")
out = stdout.readlines()
for o in out:
# print o
logfile.write(o)
# print '%s\tOK\n'%(ip)
ssh.close()
except :
print '%s\tError\n'%(ip)
logfile.close()
if __name__=='__main__':
username = "root"
passwd = "admin1"
threads = []
print "Begin......"
for i in range(1,20000):
ip = '192.168.1.113'
cmd1 ='perror '+str(i)
cmd = [cmd1]
# print i
ssh2(ip,username,passwd,cmd);
[root@localhost ~]# cat test_nothread.py
impor