Visit Our UNIX and Linux User Community


Expect help/interaction with switch..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect help/interaction with switch..
# 1  
Old 08-05-2009
Expect help/interaction with switch..

Hi All, I have been trying to get an Expect program to communicate with a Remote Power Switch which will eventually log in, and then turn on/off certain outlets. For some reason, I can't get through the log in procedure with this Switch. When you first spawn the telnet, you get the Switch info/header, and then a Password prompt, but for some
strange reason, the first time you send the password, it gets ignored, and repeats the whole header.. ok, but I try to send the password again, and the Expect script sits there and eventually times out.. I ripped out the log in procedure and made it very simple just to try to get through the log in procedure to get to the main menu of the switch, even this small piece of code doesn't work... So, I'm a bit
frustrated.. Maybe it's been too much for my eyes and it's a trivial problem but here is the piece of code... Can anyone help make heads or tales of why I can't get past this darn point. When the log in procedure is successful, I should get the Enter > prompt, but I can't get here. Thanks in advance...

#!/opt/ActiveTcl-8.4/bin/tclsh

package require Expect

log_user 1
exp_internal 1

set timeout 20

spawn telnet 1XX.1XX.1XX.149

expect "*Password > "

after 1000

send "PASS\r"

expect "*Enter > "

And here is the output I get with the debug levels turned up:

# ./johnTest
spawn telnet XXX.112.XXX.149
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {27205}

expect: does "" (spawn_id exp4) match glob pattern "*Password > "? no
Trying XXX.112.XXX.149...

expect: does "Trying XXX.112.XXX.149...\r\n" (spawn_id exp4) match
glob pattern
"*Password > "? no
Connected to XXX.112.XXX.149.
Escape character is '^]'.

expect: does "Trying xXx.112.XXX.149...\r\nConnected to XXX.112.XXX.
149.\r\nEsc
ape character is '^]'.\r\n" (spawn_id exp4) match glob pattern
"*Password > "?
no

iPal Version 2.3e
Please Enter The Password >
expect: does "Trying XXX.112.XXX.149...\r\nConnected to XXX.112.XXX.
149.\r\nEsc
ape character is '^]'.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n\r\n\
r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\niPal Version 2.3e\r\n
\r Please
Enter The Password > " (spawn_id exp4) match glob pattern "*Password >
"? yes
expect: set expect_out(0,string) "Trying XXX.112.XXX.149...\r
\nConnected to XXX
.112.XXX.149.\r\nEscape character is '^]'.\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n\r\n\
r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r
\niPal Versio
n 2.3e\r\n\r Please Enter The Password > "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "Trying XXX.112.XXX.149...\r\nConnected
to XXX.1
12.XXX.149.\r\nEscape character is '^]'.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r
\n\r\n\r\
n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\niPal
Version
2.3e\r\n\r Please Enter The Password > "
send: sending "PASS\r" to { exp4 }

expect: does "" (spawn_id exp4) match glob pattern "*Enter > "? no
PASS

expect: does "PASS\r\n" (spawn_id exp4) match glob pattern "*Enter >
"? no
expect: timed out
#
# 2  
Old 08-05-2009
To me it looks like the telnet connection is taking so long that expect times out waiting for the:

expect "*Password > "

prompt.

I would drop the "*" from before the Password to avoid that being expanded into a file list, expect can look for a word at the end of a line e.g.

expect "password:"

would work for the line:

"Please enter the password:"

If the telnet is taking a long time to connect then the setting:

set timeout 20

may be too short, I think I would get rid of the "set timeout 20" line and the "after 1000", I haven't ever needed to use either.




Previous Thread | Next Thread
Test Your Knowledge in Computers #590
Difficulty: Easy
In a linear search algorithm, the input size is the number of elements in the collection (n) divided by 2.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using expect to switch users in a script

hi, I need to switch users in a script I'm newbee to expect I wrote two files 1 sudo.exp, since su4098 is used as root in my laptop #!/usr/bin/expect spawn su su4098 expect *Password:* send mypsw\n interact 2 test.sh ls ./sudo.exp tcpdump -i wlan0 su esolve ls however, in... (1 Reply)
Discussion started by: esolve
1 Replies

2. Shell Programming and Scripting

Avoid interaction into script

Sorry for my english! I'm using Debian squeeze and for an assignement, i have create 2 virtual pdf cups printers. Both are working very well. To test the different administion command; i try to disable one of the printer and move his queue file to the second one. I'm able to do it easily. ... (4 Replies)
Discussion started by: lyapma
4 Replies

3. UNIX for Advanced & Expert Users

PAM and vsftp interaction

If I use to PAM to validate a vsftp user using a remote service to do the validation and the user does not exist on the system locally, then what becomes the home directory for the user logging in via vsftp? Assuming that chroot_user_list is enable to limit all users to their home directory. (0 Replies)
Discussion started by: ChrisC
0 Replies

4. Shell Programming and Scripting

Switch to different user without expect

Hi, I have to switch to a different user and execute certain commands and then come back to the original user Ex: My id is 'usstage'. I need to switch to 'apstage', souce a script there, execute a function and then get back again to usstage. Please note that I do not have expect installed... (4 Replies)
Discussion started by: sugan
4 Replies

5. Shell Programming and Scripting

how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable

hi, how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable which needs to be connected to one console server having rj11 on its side and db 9 female on other end.i.e. on switch side,console cable has rj45 and db 9 pin female connector on other side of... (1 Reply)
Discussion started by: pankajd
1 Replies

6. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

7. UNIX for Dummies Questions & Answers

Expect command to switch user

Hi I have written a script to switch user and do some operations. I used expect command it doesn't work. It switches the user and waits for the Password to be entered manually. Also, i tried to fetch the pasword from passwd file, it didn't work.The script is as below: ... (4 Replies)
Discussion started by: Sapna_Sai
4 Replies

8. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

9. Shell Programming and Scripting

ksh and awk interaction

in a ksh script, i want to process some string variables using awk, and then i want to go on using this variables in the same ksh (out of awk lines) can anybody send me a very simple example about this? (0 Replies)
Discussion started by: gfhgfnhhn
0 Replies

10. HP-UX

Boot interaction

Hi All, I am the new boy on the Block with HP-UX. To get to the point, I have a Hp-ux (C200) workstation running on Hp-ux 11.x Operating System. A week ago when practicing on file access permission, I have set the permission on a directory (perhaps a file I am not sure) to 0544 and did... (19 Replies)
Discussion started by: mhossien
19 Replies

Featured Tech Videos