import paramiko def sshcmd(ip, port,username,password,command): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip, port, username, password) stdin, stdout, stderr = ssh.exec_command(command) stdout_info = stdout.readlines() for ii in stdout_info: print ii #err_info = stderr.readlines() #if err_info: # print("{} is failed: {}".format(ip,err_info)) #else: # print("{} is successful: {}".format(ip, stdout_info)) ssh.close() iplist = { "192.168.1.10":[22,"root","asawwkl&00"], } for ip in iplist: print "#" * 50 +"%s"%ip + "#" * 50 #sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ df -Th """) #sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ ntpq -p ;df -h;ps -x """) #sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ sed -i '21 iserver 192.168.1.132' /etc/ntp.conf """) #sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ cat /etc/ntp.conf |grep "server 192.168.1.132" ;ps -eaf |grep ntp |grep -v grep """) #sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ /bin/systemctl restart ntpd.service ; systemctl enable ntpd.service ; systemctl is-enabled ntpd.servicE """) sshcmd(ip, iplist[ip][0], iplist[ip][1], iplist[ip][2], """ systemctl is-enabled ntpd ;systemctl list-unit-files |grep ntp """)