当前位置: 首页 > Linux, Python > 正文

python模块paramiko与ssh

#!/usr/bin/python
#-*- coding: utf-8 -*-
import paramiko
#paramiko.util.log_to_file('/tmp/sshout')
def ssh2(ip,username,passwd,cmd):
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(ip,22,username,passwd,timeout=5)
        stdin,stdout,stderr = ssh.exec_command(cmd)
#           stdin.write("Y")   #简单交互,输入 ‘Y’
        print stdout.read()
#        for x in  stdout.readlines():
#          print x.strip("n")
        print '%s\t [ %s ] OK!\n'%(ip,cmd)
        ssh.close()
    except :
        print '%stErrorn'%(ip)
ssh2("10.20.0.200","sysadmin","1q2w3e!@#","alerts show current")
ssh2("10.20.0.200","sysadmin","1q2w3e!@#","nfs export show list")
ssh2("10.20.0.200","sysadmin","1q2w3e!@#","nfs show active")
ssh2("10.20.0.200","sysadmin","1q2w3e!@#","mtree list")
ssh2("10.20.0.200","sysadmin","1q2w3e!@#","mtree show compression /data/col1/hisdb")

本文固定链接: http://t.yjsec.com/index.php/2018/04/17/529/ | 下一站

该日志由 admin 于2018年04月17日发表在 Linux, Python 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: python模块paramiko与ssh | 下一站

python模块paramiko与ssh:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter