Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1734157
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2015-07-17 09:24:39

最近常用pramiko ,都成模式了。

点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import paramiko

  4. host=your_ip
  5. username="root"
  6. password=your_pass
  7. SHOW_CWD='pwd'

  8. try:
  9.     client = paramiko.SSHClient()
  10.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  11.     client.connect(host, username=username,password=password, timeout=30)
  12.     (stdin, stdout, stderr) = client.exec_command(SHOW_CWD)
  13.     rc = stdout.channel.recv_exit_status()
  14.     output = stdout.read().decode()
  15.     if rc==0:
  16.         print(output)
  17. except Exception as e:
  18.     print("%s excepion happenend ",e)
  19. finally:
  20.     client.close()
阅读(1498) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~