linux paramiko學習

遠程執行名稱(一臺)

#!/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()

多臺

#!/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()

[root@localhost ~]# cat ip.list 

192.168.1.60    22   root    111111

192.168.1.61    22   root    111111


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章