#! /usr/bin/env python#coding:utf-8# through the Paramiko module to obtain information about the specified process of the remote machine; import paramiko host_lists= ( ' node1 ', ' 172.16.41.151 '), (' Node2 ', ' 172.16.41.152 '), (' Node3 ', ' 172.16.41.153 '), (' Node4 ', ' 172.16.41.158 ') ) def getserverinfo (host, user,password,services): conn = paramiko. Sshclient () conn.load_system_host_keys () conn.set_ Missing_host_key_policy (Paramiko. Autoaddpolicy ()) conn.connect (Host,22,user,password) stdin,stdout,stderr = conn.exec_command ("Ps aux|awk ' {print $3,$4,$5,$6,$11} ' |grep %s " % services) info = stdout.read () conn.close () return info if __name__ == ' __main__ ': print ' hostname %cpu %mem vsz rss services " for host in host_lists: try: info = getserverinfo (host[1], ' root ', ' passwd ', ' cupsd ') info_list = info.split () print "%s %s %s %s %s %s " % (host[0],info_list [0],info_list[1],info_list[2],info_list[3],info_list[4] ) except: pass
Bulk viewing of information about specified processes on remote machines using the Paramiko module