Python Bulk Modify root password

Source: Internet
Author: User

#_ *_coding:utf8_*_from multiprocessing import process, poolimport paramikoimport  sys,oshost_list =  (     (' 192.168.1.91 ',  ' root ', ' 654321 ', 123456),      (' 192.168.1.93 ',  ' root ',  ' 654321 ', 123456), S = paramiko. Sshclient () #绑定实例s. Load_system_host_keys () #加载本机HOST主机文件s. Set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) Def ssh_run (host_info):     ip,username,password,newpassword =  host_info    s.connect (ip,22,username,password,timeout=5)     #连接远程主机     stdin,stdout,stderr=s.exec_command (' echo %s | passwd --stdin  Root '% (newpassword))      #stdin, Stdout,stderr=s.exec_command (' DF ')      Cmd_result = stdout.read (), Stderr.read () #读取命令结果     print  ' \033[32; 1m-------------%s-----------\033[0m '  % ip, username    for line in cmd_result:          print line,p = pool (processes=2) result_list = []for h in   host_list:    result_list.append (P.apply_async (Ssh_run, [h,])   )         for res in result_list:     Res.get () S.close ()

The execution effect is as follows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/30/wKioL1ST4oDiTkwIAAGlMeYK8Dk002.jpg "title=" 1.png " alt= "Wkiol1st4oditkwiaaglmeyk8dk002.jpg"/>

This article is from the "Server" blog, so be sure to keep this source http://zhangfang2012.blog.51cto.com/6380212/1591774

Python Bulk Modify root password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.