【发布时间】:2021-02-28 21:05:08
【问题描述】:
我正在使用 Python 通过 Paramiko ssh 到远程服务器并运行 shell 脚本来执行命令
.py 文件:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=username, password=password)
print("Connected")
stdin, stdout, stderr = ssh.exec_command(myscript)
# read the standard output and print it
print(stdout.read().decode())
# print errors if there are any
err = stderr.read().decode()
if err:
print(err)
ssh.close()
Unix 脚本:
cd /usr/data
pwd
read -r username
echo "$username"
输出将是:
/usr/data
不允许输入用户名变量,不显示。
如何使用 Python(pycharm ide)和 Unix 实现这一点?
【问题讨论】:
标签: python shell unix ssh paramiko