公司需要新上项目,上架20台机器,要对这些主机进行改名
代码语言:javascript复制#!/usr/bin/env python
from multiprocessing import Process, Pool
import paramiko
import sys,os
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
def ssh_run(host_info):
ip=host_info[0]
username=host_info[1]
password=host_info[2]
hostname=host_info[3]
s.connect(ip,22,username,password,timeout=5)
stdin,stdout,stderr=s.exec_command("sed -i '/HOSTNAME/s/localhost.localdomain/%s/' /etc/sysconfig/network"%hostname)
cmd_result = stdout.read(),stderr.read()
print '