Multiple Telnet sessions through one script

V

vmalhotra

Hi

I am new in python scripting. I want to open a Multiple telnet session
through once script. In other way i can tell i want to open two linux
consoles through one script.

I wrote one script, but the issue is I am not able to open multiple
consoles. The Scripts which i wrote is as follows:

import pexpect
session = pexpect.spawn("telnet localhost 2601\n")
session.expect("Password: ")
session.send("XYZ\n\n")
session.expect("Router1> ")
session1 = pexpect.spawn("telnet localhost 2604\n")
session1.expect("Password: ")
session1.send("ABCD\n\n")
session1.expect("ospfd> ")
#session1.interact()
session1.interact()

output :
ospf>

But in this case, i want in one console router one can open and on
other console ospf should open. But this i want to do is through one
script only.

Regds
Vik
 
C

Carl J. Van Arsdall

Well, although you spawn seperate telnet processes there is still only
one thread of control in your pythons script. If you need to do two
things simultaneously you'll need to setup a parallel control
mechanism. For example you could use python threads, each thread spawns
a separate telnet and controls it accordingly. Similarly, you could
fork off other python scripts that control each telnet session.

Alright, so that's for controlling two telnets at once. I think you'll
have another problem, and that's controlling each telnet session
manually. To do this I think you'll need to setup an interface that
provides the two consoles you are after. I'm not exactly sure the best
way to do that. One thought I have is if you used one of the various
GUI toolkits you could have your app open a window that is seperated
into two consoles. Each thread could be bound to one of these consoles
and you could switch between the two by clicking on one side versus the
other. Although if you want to do it all in a shell, or have your
program open multiple shells I'm not sure how to do that, you might
check google. I suppose if you were doing things from a single shell
and wanted to do thing similar to the GUI toolkit I described earlier,
you could try something like ncurses.

I guess I have one final idea, you could use a single shell, buffer
output from each telnet session and have your main control loop give you
the ability to switch back and forth between the two sessions.

Anyhow, hope those ideas help you out a little.
Hi

I am new in python scripting. I want to open a Multiple telnet session
through once script. In other way i can tell i want to open two linux
consoles through one script.

I wrote one script, but the issue is I am not able to open multiple
consoles. The Scripts which i wrote is as follows:

import pexpect
session = pexpect.spawn("telnet localhost 2601\n")
session.expect("Password: ")
session.send("XYZ\n\n")
session.expect("Router1> ")
session1 = pexpect.spawn("telnet localhost 2604\n")
session1.expect("Password: ")
session1.send("ABCD\n\n")
session1.expect("ospfd> ")
#session1.interact()
session1.interact()

output :
ospf>

But in this case, i want in one console router one can open and on
other console ospf should open. But this i want to do is through one
script only.

Regds
Vik


--

Carl J. Van Arsdall
(e-mail address removed)
Build and Release
MontaVista Software
 
C

Cameron Laird

Well, although you spawn seperate telnet processes there is still only
one thread of control in your pythons script. If you need to do two
things simultaneously you'll need to setup a parallel control
mechanism. For example you could use python threads, each thread spawns
a separate telnet and controls it accordingly. Similarly, you could
fork off other python scripts that control each telnet session.

Alright, so that's for controlling two telnets at once. I think you'll
have another problem, and that's controlling each telnet session
manually. To do this I think you'll need to setup an interface that
provides the two consoles you are after. I'm not exactly sure the best
way to do that. One thought I have is if you used one of the various
GUI toolkits you could have your app open a window that is seperated
into two consoles. Each thread could be bound to one of these consoles
and you could switch between the two by clicking on one side versus the
other. Although if you want to do it all in a shell, or have your
program open multiple shells I'm not sure how to do that, you might
check google. I suppose if you were doing things from a single shell
and wanted to do thing similar to the GUI toolkit I described earlier,
you could try something like ncurses.

I guess I have one final idea, you could use a single shell, buffer
output from each telnet session and have your main control loop give you
the ability to switch back and forth between the two sessions.

Anyhow, hope those ideas help you out a little.
.
.
.
While pexpect makes these matters feasible, the Tcl-based
Expect <URL: http://wiki.tcl.tk/expect > has had years more
practice dealing with concurrency and its consequences. If
this problem were mine, I'd start with Expect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top