Automation Python SSH自动化为一个命令提供空白结果
您好,我正在尝试为特定设备使用Python for SSH实现自动化 我正在运行这样的输出,以便在控制台中显示列出的命令Automation Python SSH自动化为一个命令提供空白结果,automation,paramiko,Automation,Paramiko,您好,我正在尝试为特定设备使用Python for SSH实现自动化 我正在运行这样的输出,以便在控制台中显示列出的命令 stdin, stdout, stderr = pre_ssh_conn.exec_command(command1) output1 = stdout.read().decode('ascii').strip("\n") stdin, stdout, stderr = pre_ssh_conn.exec_command(command2) output2 = stdout.
stdin, stdout, stderr = pre_ssh_conn.exec_command(command1)
output1 = stdout.read().decode('ascii').strip("\n")
stdin, stdout, stderr = pre_ssh_conn.exec_command(command2)
output2 = stdout.read().decode('ascii').strip("\n")
stdin, stdout, stderr = pre_ssh_conn.exec_command(command3)
output3 = stdout.read().decode('ascii').strip("\n")
print("Command Output: ", output1)
print("\nCommand Output: ", output2)
print("\nCommand Output: ", output3)
print('\n\nINFO: Commands Executed Successfully')
除了一个特定的命令外,所有的命令似乎都给我一个输出
跑步时
asg stat vs all
在SSH上,我得到了一个结果,-[SSH不带python脚本]
但是当通过python自动化脚本运行它时:我得到一个空的空行。
我想知道是否有人能告诉我为什么我会通过ssh得到结果,而不是通过python脚本(所有其他命令,如正常运行时间等,似乎都会在python终端中显示输出,所以我知道代码应该可以工作)
我唯一能想到的是通过SSH,第二个命令首先提供一个空行,例如:
SSH输出
[User@BLAHBLAHBLAHBLAH:ACTIVE]# uptime
16:15:30 up 299 days, 21:24, 1 user, load average: 1.19, 1.22, 1.03
[User@BLAHBLAHBLAHBLAH:ACTIVE]# asg stat vs all
Chassis vs all is supported with Dual Chassis only.
[User@BLAHBLAHBLAHBLAH:ACTIVE]#
终端中的我的代码输出:
命令输出:16:05:45最多299天,21:14,2个用户,平均负载:0.88,0.88,0.83
命令输出:
编辑
[User@BLAHBLAHBLAHBLAH:ACTIVE]# uptime
16:15:30 up 299 days, 21:24, 1 user, load average: 1.19, 1.22, 1.03
[User@BLAHBLAHBLAHBLAH:ACTIVE]# asg stat vs all
Chassis vs all is supported with Dual Chassis only.
[User@BLAHBLAHBLAHBLAH:ACTIVE]#
在下面的评论中,即使使用using方法也会给我一个奇怪的输出
stdin, stdout, stderr = pre_ssh_conn.exec_command("bash --login -c " + "asg resource")
Command Output: Usage: [opt]
Options:
stat - Chassis status
monitor - Monitor system status
perf - Run performance tool
hw_monitor - Display hardware monitor
resource - Display resources table
search - Search for a connection in the gateway
alert - Configure system alerts sending
policy - Control and monitor policy status
if - Display interfaces table
dxl - Configure distribution options
security_group - Display/change the computing blades in the Security Group
diag - Display system diagnostics
log - Display aggregated logs
sgm_admin - Configure administrative state for an SGM
chassis_admin - Configure administrative state for a chassis
synatk - Monitor syn defender status
f2fq - Monitor f2f quota status
profile - Monitor services statistics
vsx_verify - Display summary of VSX configuration over all SGMs
请参阅。查看添加get#pty=True(尽管不建议)的链接,将显示未找到命令,但仅针对命令2而不是命令3。command2=“asg stat vs all”command3=“asg resource”应该类似于
“bash--login-c\“asg resource\”
这是否回答了您的问题?请参阅。查看添加get#pty=True(尽管不建议)的链接,将显示未找到命令,但仅针对命令2而不是命令3。command2=“asg stat vs all”command3=“asg resource”应该类似于“bash--login-c\“asg resource\”
这是否回答了您的问题?