Sponsored Content
Top Forums Programming Pexpect telnet into one device and then from there to another Post 302766395 by kaf3773 on Monday 4th of February 2013 04:16:06 PM
Old 02-04-2013
Pexpect telnet into one device and then from there to another

I am trying to use pexpect to telnet to a device and then subsequently
telnet from that device to another device but i am unable to. Here is the
script i wrote and the error i am getting

I will appreciate help very much. Thanks

Code:
import pexpect

child = pexpect.spawn('telnet 192.168.2.45');

child.expect('assword:');
child.sendline('getin');

child.expect('AS-C5350-02>');
child.sendline('telnet 192.168.1.2'); 
child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
child.sendline('cisco'); 
child.expect('ipipgw01>'); 
child.sendline('sh clock');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;

This is the error i keep getting

Code:
Traceback (most recent call last):
  File "expect_telnetback.py", line 14, in <module>
    child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
    raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0xb7752a2c>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/telnet
args: ['/usr/bin/telnet', '192.168.2.45']
searcher: searcher_re:
    0: re.compile("
Trying 196.192.7.14 ... Open


User Access Verification

Password:")
buffer (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
before (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 26275
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remote monitoring of device by telnet

There is programm of monitoring by telnet. The main body of script is mkfifo pipe0 telnet $host $port < pipe0 > file0 & then after analizing of file0 printf "commands\r" > pipe0 This programm worked till then I kill pipe0 during working of programm. Now this script dont... (1 Reply)
Discussion started by: ILA
1 Replies

2. AIX

Telnet disconnects on handheld device AIX

I have intermec handheld device which is connecting to AIX Server on port 12431 or whatever. ( oracle application ) The handheld device connects for few seconds and then disconnects from the AIX server. Once it disconnects the handheld device automatically switches off. Are there any... (2 Replies)
Discussion started by: filosophizer
2 Replies

3. Ubuntu

Ubuntu 9.04 Serial application to telnet to serial device

Hello! I am working on an application which reads environmental instruments which have serial ports. The application requires a serial port to be present to talk to the device (i.e. /dev/ttyS0 ). In some instances the environmental devices will be 100's of yards away from the computer, so a... (5 Replies)
Discussion started by: mvona
5 Replies

4. Red Hat

Unable To Activate Ethernet Network Device in RHEL 5.5 - e100 device eth0 does not seem to be presen

Hi All, Could anyone please help to resolve the below problem. I installed RHEL5.5 in my desktop.But when i try to activate the ethernet connection then it gives me the error. I spent 2 days for the above and go through with several suggestion found by googling. But no luck. ... (0 Replies)
Discussion started by: Tanmoy
0 Replies

5. HP-UX

Failed to open tape device /dev/rmt/0mn:Device busy (errno = 16)

Hi, Unable to make tape backup, please help. /opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00 * Creating local directories for configuration files and archive. ======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery. (Mon... (4 Replies)
Discussion started by: anuragr
4 Replies

6. Programming

Edit a file using pexpect python

Hi I am damn new to this python scripting I have arrived till getting into the console of a machine using pexpect Now I just wanted to know how to list/edit the contents of a file using pexpect Please help:confused: (0 Replies)
Discussion started by: Priya Amaresh
0 Replies
TELNET-PROBE(1) 					      General Commands Manual						   TELNET-PROBE(1)

NAME
telnet-probe - lightweight telnet-like port probe SYNOPSIS
$PCP_BINADM_DIR/telnet-probe [-c] [-v] host port DESCRIPTION
telnet-probe allows the pmdashping(1) daemons to establish connections to arbitrary local and remote service-providing daemons so that response time and service availability information can be obtained. The required host and port number arguments have the same meaning as their telnet(1) equivalents. The -c option causes telnet-probe to perform a connect(2) only. This skips the read(2) and write(2) exercise that would otherwise be done after connecting (see below). The -v option causes telnet-probe to be verbose while operating. Once the telnet connection has been established, telnet-probe reads from stdin until end-of-file, and writes all the input data to the tel- net connection. Next, telnet-probe will read from the telnet connection until end-of-file, discarding whatever data it receives. Then telnet-probe exits. To operate successfully, the input passed via telnet-probe to the remote service must be sufficient to cause the remote service to close the connection when the last line of input has been processed, e.g. ending with ``quit'' when probing SMTP on port 25. By default telnet-probe will not produce any output, unless there is an error in which case a diagnostic message can be displayed (in ver- bose mode only) and the exit status will be non-zero indicating a failure. PCP ENVIRONMENT
Environment variables with the prefix PCP_ are used to parameterize the file and directory names used by PCP. On each installation, the file /etc/pcp.conf contains the local values for these variables. The $PCP_CONF variable may be used to specify an alternative configura- tion file, as described in pcp.conf(5). DIAGNOSTICS
If telnet-probe succeeds, then 0 will be returned. If the attempt to establish a connection fails or is terminated, then a non-zero exit status is returned. SEE ALSO
PCPintro(1), pmdashping(1), pmie(1), telnet(1), connect(2), read(2) and write(2). Performance Co-Pilot PCP TELNET-PROBE(1)
All times are GMT -4. The time now is 03:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy