我想使用paramiko自动获取当前内核版本。我尝试使用python.I连接到服务器(网络操作系统),然后尝试执行以下命令
OS10# system bash
admin@OS10:~$ uname -r
3.16.51下面是我的python脚本
import sys
import time
import select
import paramiko
host = '100.97.100.12'
i = 1
while True:
print "Trying to connect to %s (%i/30)" % (host, i)
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host,port=22,username="admin",password="admin",
timeout=float(10),allow_agent=False ,look_for_keys=False)
print "Connected to %s" % host
break
except paramiko.AuthenticationException:
print "Authentication failed when connecting to %s" % host
sys.exit(1)
except:
print "Could not SSH to %s, waiting for it to start" % host
i += 1
time.sleep(2)
# If we could not connect within time limit
if i == 30:
print "Could not connect to %s. Giving up" % host
stdin, stdout, stderr = ssh.exec_command("system bash")
ssh_output = stdout.read()
ssh_error = stderr.read()
print(ssh_output)
print(ssh_error)
ssh.close()我可以连接到主机,但它没有给任何error没有output时,执行该命令。
发布于 2019-03-13 18:19:51
尝试执行以下命令:
/path/to/bash -c 'uname -r'
在那里,您可以通过SSHing连接到您的服务器并查看cat /etc/shells或which bash上的path/to/bash路径来确定bash。或者,您可以使用chsh永久更改默认shell。
https://stackoverflow.com/questions/55123931
复制相似问题