#!/usr/bin/env python
#Kiss Python
############## ##### ip.list #################################
# 172.16.13.118:root:centos:hostname: #
# 172.16.5.114:root:centos:hostname:whoami:w:ifconfig eth0: #
##########################################################
import paramiko
file = open(‘ip.list‘)
for line in file:
ip = str(line.split(‘:‘)[0])
username = str(line.split(‘:‘)[1])
password = str(line.split(‘:‘)[2])
cmds = (line.split(‘:‘)[3:-1])
print "######################",ip,"#######################"
s=paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(ip,22,username,password)
for cmd in cmds:
print "\033[1;32m[\‘%s\‘] \033[0m" % cmd
stdin,stdout,sterr=s.exec_command(cmd)
print stdout.read()
s.close()
file.close()
本文出自 “Crazy_Linux” 博客,请务必保留此出处http://mkernel.blog.51cto.com/8015041/1598341
原文地址:http://mkernel.blog.51cto.com/8015041/1598341