473,231 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 7617
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: john | last post by:
How do u guys handle multiple sessions?? i.e, opening different browser windows by running iexplore.exe or clicking IE icons and opening the application. My sessions are mixing up. what i mean is...
4
by: Pekka Niiranen | last post by:
Hi, I have a multiuser script, that I would like to convert to Python. The users open simultaneous telnet -sessions from win2000 to an unix machine and possibly edit unicode textfiles. Currently...
6
by: Richard Bird CCNP, CCDP, MCSE, etc. | last post by:
I need some help adding multithreading to an existing python script. The script was developed to telnet and make changes on a list of cisco routers. I figure that by adding multithreading, I'd be...
1
by: Tony Pryor | last post by:
Hello, Anyone know if running two client telnet sessions at the same time should be an inherent problem? They don't seem to want to share a port or are they trying to use the same console for...
1
by: Michael | last post by:
Dear all, Given the following challenge: 1. The application is an exe on a W2K server 2. User logs via telnet to the server 3. After checking the user account and password, a bat file runs...
1
by: Siva Palaninathan | last post by:
Hi, I am trying to automate telnet sessions to retrive information from a linux box. The box is not running a full-featured version of linux, embedded linux, has very limited sources, memory,...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
2
by: thamayanthi | last post by:
Hi, The below code is used to connect to the remote machine using Telnet module in perl. use Net::Telnet; use Net::Ping; $telnet = new Net::Telnet (Timeout=>10,Errmode=>'die'); open...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.