1

Hello I am trying to do automation using Python for SSH for a specific device.

I am running output like this to display in the console the commands that are listed.

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')

All commands seem to give me an output except one specific command.

When running

asg stat vs all

on SSH I am getting a result, - [ SSH without my python script ] but when running it via my python automation script: I am getting an empty blank line. I was wondering if someone could give me insight as to why I would be getting a result via ssh, but not via my python script (all other commands such as uptime, etc seem to display an output in the python terminal, so I know the code should work.)

The only thing I can think of is via SSH the second command provides a blank line first, for example:

SSH Output

[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]#

My code output in terminal:

Command Output: 16:05:45 up 299 days, 21:14, 2 users, load average: 0.88, 0.88, 0.83

Command Output:

Edit

Following bellow comment, even using using method gives me a strange output.

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

0 Answers0