Linux Paramiko Learning

Source: Internet
Author: User

Remote execution name (one)

#!/usr/bin/env python

Import Paramiko

Paramiko.util.log_to_file ('/tmp/test ')

Ssh=paramiko. Sshclient ()

Ssh.load_system_host_keys ()

Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

Ssh.connect (' 192.168.1.61 ', port=22,username= ' root ', password= ' 111111 ', compress=true)

Stdin,stdout,stderr=ssh.exec_command (' hostname ')

Print Stdout.read ()

Ssh.close ()

Multiple units

#!/usr/bin/python

Import Paramiko

Port=22

Username= ' Root '

File=open (' ip.list ')

For line in file:

Ip=str (Line.split () [0])

Password=str (Line.split () [3]). Strip ()

Print "##########################", IP, "########################"

S=paramiko. Sshclient ()

S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

S.connect (Ip,port,username,password)

Stdin,stdout,sterr=s.exec_command (' Df-hl ')

Print Stdout.read ()

S.close ()

File.close ()

[email protected] ~]# cat Ip.list

192.168.1.60 Root 111111

192.168.1.61 Root 111111


This article from "not be worried about the second second Worry" blog, please be sure to keep this source http://ghnhl.blog.51cto.com/1630025/1558596

Linux Paramiko Learning

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.