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