Python's brevity is not a substitute for the shell.

Source: Internet
Author: User

Before the online server distribution configuration is the shell and expect script distribution, the script is written for a long time, last week changed the Ansible, and now write one in Python, 30 lines of code to achieve the requirements, the previous Shell wrote a fast 200 lines, egg pain, the code is as follows:

From multiprocessing import processimport paramikoimport sysfile = sys.argv[1]username = "root" Password = "123456" Dest_pa th = ["/data/x5online/%s"%file, "/tmp/%s"%file]port = 22def sftpput (IP): try:s = Paramiko. Transport ((Ip,port)) S.connect (username=username,password=password) sftp = Paramiko. Sftpclient.from_transport (s) localfile = file for remotefile in Dest_Path:sftp.put (localfile,rem Otefile) Print ("%s put successful."%ip) Except:print ("%s not exits.") %IP) def ipprocess (): For I in Range (10,40): ip = ' 192.168.170.%s '%i p = Process (target=sftpput,args= (IP,)                                                                                                                                                                                         ) P.start () if __name__ = = ' __main__ ': ipprocess ()                                                                                                           

Chicken soup Once, interested in Python, learn quickly, like last year to Linux is very obsessed with, a year, now I am a game company's operation and maintenance leader. Come on

Python's brevity is not a substitute for the shell.

Related Article

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.