Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Paramiko, continuing the interaction for a command in interactive shell
I have been trying to automate a task using python, in which I ssh to a remote server using paramiko, bring up the interactive shell and run the command.
The problem I'm facing is that the command I execute requires further more inputs to be given to it . Consider the below example, which happens on the cli, if the command is manually executed on the server

Select the config to restore
a.conf b.conf.c.conf
Are you sure you want to proceed(Y/N)?
******the execution begins and completes by itself*****

The problem with my code is after the restore-config is executed, the paramiko channel gets closed without asking the input(in case of above example,"select the config to restore"),it displays restore-config aborted, how can I carry on the interaction?
My code is as follows:

import paramiko

ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
ssh.connect( '',username='abcd',pass='1234' )


def run_cmd(cmd):

     for l in stdout:
        print "stdout:%s" %l.strip()

     for l in stderr:
         print "Error:%s" %l.strip()


      for l in stdout:
        print "stdout:%s" %l.strip()

      for l in stderr:
         print "Error:%s" %l.strip()


        for l in stdout:
            print "stdout:%s" %l.strip()

        for l in stderr:
            print "Error:%s" %l.strip()

The output is similar as follows

stdout:Select the configuration file stdout:a.conf stdout:b.conf stdout:c.conf stdout:restore aborted

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  paramiko/ssh-matic not working from Windows Server 2012 R2 machine having Python34. pythonuser14 1 296 Oct-15-2017, 06:53 AM
Last Post: pythonuser14
  Python error handling Paramiko pythondiy 2 1,276 Aug-22-2017, 02:22 AM
Last Post: oldseven
  How to keep paramiko ssh session open after loggin in using python? MikeHill 3 1,055 Aug-15-2017, 06:55 PM
Last Post: nilamo
  SSH to a device using paramiko fails MikeHill 0 474 Aug-07-2017, 08:12 PM
Last Post: MikeHill
  Is this fast for Paramiko? gohanzdad 3 903 May-06-2017, 05:59 AM
Last Post: gohanzdad

Forum Jump:

Users browsing this thread: 1 Guest(s)