last day (20 days later) » 

1:03 AM
1
A: ssh connection not persistent

kichikEvery command you execute using exec_command has a channel of its own and therefore a context of its own. That context includes the working directory. You change the working directory in one context and then try to use it in another. Instead, use the same channel for all the commands. You can eit...

 
am looking for a way where ssh connection is open and I have the flexibility to run mulitple commands independently...
am not clear when you said Adding cd to each command you run would be the simplest solution ,can you explain a bit more? also,can you give an example for You can also open a channel or use invoke_shell() to get the exact same features
@ kichikk - the problem is its just not these commands,i have a lot of commands to execute once the ssh connection is open,its kind of difficult to to keep adding &&
 
@user2125827: for opening a channel, you could try the solution that was posted here in response to a similar question.
 
@ErlendGraff - using the channel ,will I be able to execute back to back commands,like chan.exec_command('cd dir/path') chan.exec_command(git cherry-pick)`,I want to be able to send many consecutive commands
 
@user2125827: If you do chan = ssh.invoke_shell() instead of chan = ssh.get_transport().open_session() and chan.get_pty(), then you should be able to execute commands back-to-back using chan.send() and chan.recv() instead of chan.exec_command(). Note: you may have to send explicit newlines, such as chan.send('cd somefolder\n'), chan.send('ls\n').
 
@ErlendGraff - I updated the latest code and latest error I get,can you help me how to overcome this?where should I exactly use chan.send() and chand.recv()
@ErlendGraff --> updated again with chan.invoke_shell() and running into same error
 
1:03 AM
@user2125827: If you use invoke_shell(), try to remove the call to chan.get_pty().
 
@ErlendGraff --> how do I send chan.send(cmd_val) this like a new line?I dont think the commands are working as the git command is not cherrypicked
 
@user2125827: couldn't you just do chan.send(cmd_val + '\n')?
 
@ErlendGraff - I did try that but I dont think the commands are getting executed as I dont see the git command being successful..
@ErlendGraff -- your suggestions are the closest i got to my answer,any reason we can debug why these commands are not working?I dont get any error
 
 
11 hours later…
12:25 PM
Could you try something like this:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(resource, username='username', password='passwordname')
chan = ssh.get_transport().open_session()
chan.setblocking(0)
chan.exec_command("bash --login") # Assuming you have bash on your ssh box
chan.send("ls\n")
print chan.recv(9999)
chan.send("cd frameworks/base\n")
chan.send("ls\n")
print chan.recv(9999)
 
 
6 hours later…
6:32 PM
I tried the following
resource = r'qca-cdit-01'
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(resource, username='cdit', password='Cnssdev10')
chan = ssh.get_transport().open_session()
chan.setblocking(0)
chan.exec_command("bash --login") # Assuming you have bash on your ssh box
chan.send("ls\n")
print chan.recv(9999)
chan.send("cd /local/mnt/workspace/LA_host_builds/AU_LINUX_ANDROID_LA.BF64.1.2.1_RB2.05.01.01.081.031_msm8992\n")
print chan.recv(9999)
I get the following error
Traceback (most recent call last):
  File "ssh_test.py", line 22, in <module>
    print chan.recv(9999)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 598, in recv
    raise socket.timeout()
socket.timeout
 
 
4 hours later…
10:31 PM
Is line 22 the last call to chan.recv(9999)?
Because, in that case, the timeout is probably just cased by the git command taking some time to complete
 
even if I remove all the other chan.send command and just leave chan.send("ls\n") ,still gives the same error
 
Maybe it's too harsh to use a non-blocking channel.
Try to do something like chan.settimeout(5.0) instead of chan.setblocking(0), and see if the ls command succeeds then
 
11:20 PM
do we have to set the timeout after every send,because I hit an the same error at print chan.recv(9999) after the chan.send("cd /local/mnt/workspace/LA_host_builds/AU_LINUX_ANDROID_LA.BF64.1.2.1_RB2.05.01.01.‌​081.031_msm8992\n")
 

  last day (20 days later) »