[paramiko] Trying to use SSH like telnet

Jeff jv.goff at gmail.com
Sat Jan 26 10:05:32 PST 2008


hi

i am struggling with trying to get paramiko to do what i have done
with telnet using telnet with perl,ruby and even python before hope
someone on the list can help me out.

I have read through the archives and seen a few related posts -
including the migrate from Telnet to SSH thread - but the suggestions
in that thread still don't solve my issue, or at least i cannot see it
yet :(

Here is the scenario - i am building a threaded (but just need it to
even work for a single device right now) script that will open an ssh
session to the device CLI, then enter a debug shell on that device,
sit there, running commands as i need them run, and returning me the
output - but not disconnecting after each command. Ultimately i am
trying to have multiple "devices" with 2 ssh sessions to device, one
in the CLI one in the debug shell, and wrap it all in a big select -
but thats getting ahead of myself, for now, i just need it to work
with one device and one ssh session.

I have looked at exec_cmd with SSHClient (but it closes the channel
after each command) and have tried the hack of a dummy_chan idea, but
it didn't work. The closest thing i have right now that i think might
work is with SSHClient invoke_shell - but if i go down that path,
seems i need to re-write / port the entire concept of telnetlib
read_until for handling prompts and waiting/gathering of all the
output from a command.

after messing with the paramiko demos, the snippets from the mailing
list and rolling-my-own for 2 days, i am at a loss, any pointers
greatly appreciated ! Surely i am not the first person who doesn't
just want to exec one command and exit, but have a script controlled
interactive shell which looks similar to telnetlib with goodies like
read_until, but is not hooked to the stdin/out of the script (i.e.
like demo_simple.py)

ps. i am pretty green at python - if i have grossly mis-stated
something here, apologies in advance.

thanks
-jeff


here is the basic skeleton i have so far

client = paramiko.SSHClient()
client.connect("1.2.3.4",22,"test","test")
chan = client.invoke_shell()
chan.setblocking(0)

chan.send("ls -la\n")
<need to handle waiting and gathering here, i.e. telnetlib ->
read_until style ?????>



More information about the paramiko mailing list