Oct-26-2016, 01:21 AM
I have written below code to run 3 command in remote server interactively
But when i checked 3rd command never executed and code stuck here is my code
When i ran i got output of ls -l but ls -lh never executed my code stuck in first while loop. Anyone please help to resolve my issue
But when i checked 3rd command never executed and code stuck here is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
def execute(): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect( 'ipaddress' ,username = 'user' , password = 'pw' ) chan = ssh.invoke_shell() # start the shell before sending commands chan.send( 'cd /path to folder/test' ) chan.send( '\n' ) time.sleep( 3 ) chan.send( "ls -l" ) chan.send( '\n' ) buff = '' while not buff.endswith( ">" ): resp = chan.recv( 9999 ) # code stuck here after 'path to folder/test >' comes in shell prompt buff + = resp print resp print "test" chan.send( "ls -lh" ) chan.send( '\n' ) time.sleep( 5 ) buff = '' while not buff.endswith( ">" ): resp = chan.recv( 9999 ) buff + = resp print resp if __name__ = = "__main__" : execute() |
When i ran i got output of ls -l but ls -lh never executed my code stuck in first while loop. Anyone please help to resolve my issue