#脚本作用:查询服务器配置信息
#用法:IP写入当前文件host.txt中再执行该脚本
#日期:2018-1-15


import paramiko
from multiprocessing import Pool

def main(hostname):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(hostname,22,"用户名","密码")
    except:
        with open("/tmp/error.txt",'a') as f:
            f.write("%s is connect error\n" % hostname)
            return 
    Cpu_num = ssh.exec_command('cat /proc/cpuinfo | grep "physical id" | uniq | wc -l')[1].read().strip()
    Cpu_code = ssh.exec_command("cat /proc/cpuinfo | grep 'cpu cores' | uniq")[1].read().strip()
    Mem = ssh.exec_command('cat /proc/meminfo | grep MemTotal')[1].read().strip()
    Disk = ssh.exec_command("""df -m|awk '$4~/^[0-9]/ {split($4,array,"[A-Z]");b+=array[1]} END {print b/1024}'""")[1].read().strip()
    Os = ssh.exec_command("cat /etc/issue | xargs")[1].read().strip()
    Ntp_PS = int(ssh.exec_command("ps -ef | grep -v grep | grep ntp | wc -l")[1].read())
    if Ntp_PS == 1:
        NtpPS = "TRUE"
    else:
        NtpPS = "False"
    Ntp = ssh.exec_command("cat /etc/ntp.conf | grep server | xargs")[1].read().strip()
    Timezone = ssh.exec_command("cat /etc/timezone")[1].read().strip()
    Swapiness = ssh.exec_command("cat /etc/sysctl.conf | grep swappiness | xargs")[1].read().strip()
    Dns_resolv = ssh.exec_command("cat /etc/resolv.conf | grep nameserver | xargs")[1].read().strip()
    Dns = ssh.exec_command("cat /etc/network/interfaces | grep dns")[1].read().strip()
    Repo = int(ssh.exec_command("cat /etc/apt/sources.list | grep uledns |wc -l")[1].read())
    if Repo >= 3:
        Repo = "True"
    else:
        Repo = "False"

    Zabbix = int(ssh.exec_command("ps -ef |grep zabbix |wc -l")[1].read())
    if Zabbix >= 3:
        Zabbix = "True"
    else:
        Zabbix = "False"

    with open("/tmp/zhoujinlong.txt",'a') as z:
        z.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" %
                (hostname,Cpu_num,Cpu_code,Mem,Disk,Os,Ntp_PS,Ntp,Timezone,Swapiness,Dns_resolv,Dns,Repo,Zabbix))

if __name__ == '__main__':
    pool = Pool(processes=10)
    f = open("host.txt")
    for i in f:
        hostname = i.strip()
        pool.apply_async(main,(hostname,))
    pool.close()
    pool.join()

如需单线程跑脚本可以这样:
if __name__ == '__main__':
    f = open("host.txt")
    for i in f:
        hostname = i.strip()
        main(hostname)