How can I send multiple commands to a remote server using python?
I had to learn python for study reasons, so I decided to try to automate the information collection of the bacula consoles.
I'm trying to use the following script, but I have not been successful.
Could you point me where I'm wrong?
HOST= 'server.name.com.br'
try:
s = pxssh.pxssh()
hostname = HOST
username = 'root'
password = 'xxxxxxx'
s.login(hostname, username, password)
s.sendline('bconsole') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.prompt() # match the prompt
s.sendline('st') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.prompt() # match the prompt
s.sendline('1') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.prompt() # match the prompt
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh failed on login.")
Thank you very much for your attention.