如何使用 SSH python 运行 tmsh (f5( 命令并获取输出?
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('1.1.1.1', username='username', password='password')
ssh.exec_command('ls') //Working
# how to execute tmsh command using ssh ?
ssh.exec_command('tmsh show /sys CPU') // ???
在解决这个问题时,我得到了解决这个问题的解决方案:
stdin, stdout, stderr = ssh.exec_command("tmsh show /sys CPU | cat")
print stdout.read()
使用此命令,我可以获取 tmsh 输出。如果没有 grep,它将在 stdout.read(( 中返回空白输出。