Use Python to execute multi-line shell scripts on a remote computer

Source: Internet
Author: User

#!/usr/bin/env pythonimport paramikohostname= ' was1 ' port=22username= ' MQM ' password= ' Redhat ' cmd= ' function printline {                 echo  "--------------------------------------------------------------"          } if [ -d /tmp/test ]then printline  check_test_direcho  "/tmp/test exist" Elsemkdir /tmp/testfi     cat  /etc/fstab>/tmp/test/fstab.bkprintline ls_testls /tmp/testprintline cat_fstab.bkcat  /tmp/test/fstab.bkprintline ip_check/sbin/ifconfig ' if __name__== ' __main__ ':p aramiko.util.log _to_file (' Paramiko.log ') S=paramiko. Sshclient () S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) #s. Load_system_host_keys () s.connect (Hostname,port,username,password) stdin,stdout,stderr=s.exec _command (CMD) print stdout.read () PRINT STDERR.READ () S.close () 


Note: The remote host must be able to resolve the host name of the host where the Python program is located, or the program executes very slowly.

Use Python to execute multi-line shell scripts on a remote computer

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.