天河超算,使用Python自动ssh

1)先上代码

复制代码
import paramiko
 
transport = paramiko.Transport(("ip地址", 22))
transport.connect(username="username", password="passwd")              # 建立连接
 
# 创建SSH对象
ssh = paramiko.SSHClient()
ssh._transport = transport
 
# 执行命令,不要执行top之类的在不停的刷新的命令
stdin, stdout, stderr = ssh.exec_command("ls ")
 
# 获取命令结果
res, err = stdout.read(), stderr.read()
result = res if res else err
print(result.decode())
 
# 关闭服务器连接
transport.close()

2)执行

python test_ssh.py

3)运行结果

相关推荐
Ccjf酷儿2 分钟前
C++语言程序设计 (郑莉)第六章 数组、指针和字符串
开发语言·c++
禹曦a3 分钟前
Java实战:Spring Boot 构建电商订单管理系统RESTful API
java·开发语言·spring boot·后端·restful
superman超哥3 分钟前
精确大小迭代器(ExactSizeIterator):Rust性能优化的隐藏利器
开发语言·后端·rust·编程语言·rust性能优化·精确大小迭代器
芒克芒克4 分钟前
虚拟机类加载机制
java·开发语言·jvm
陌路204 分钟前
C++28 STL容器--array
开发语言·c++
hui函数6 分钟前
Python系列Bug修复|如何解决 pip install -e . 安装报错 “后端不支持可编辑安装(PEP 660)” 问题
python·bug·pip
二哈喇子!9 分钟前
PyTorch与昇腾平台算子适配:从注册到部署的完整指南
人工智能·pytorch·python
FPGAI13 分钟前
Python之函数
开发语言·python
csbysj202016 分钟前
NumPy Ndarray 对象
开发语言
Z1Jxxx16 分钟前
删除字符串2
开发语言·c++·算法