468,554 Members | 1,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Multiple Telnet sessions through one script

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

Jul 31 '06 #1
2 6634
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.

vmalhotra wrote:
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
cv*********@mvista.com
Build and Release
MontaVista Software

Jul 31 '06 #2
In article <ma***************************************@python. org>,
Carl J. Van Arsdall <cv*********@mvista.comwrote:
>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.

vmalhotra wrote:
>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.
Aug 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by john | last post: by
4 posts views Thread by Pekka Niiranen | last post: by
6 posts views Thread by Richard Bird CCNP, CCDP, MCSE, etc. | last post: by
1 post views Thread by Tony Pryor | last post: by
1 post views Thread by Siva Palaninathan | last post: by
4 posts views Thread by Patricia Mindanao | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.