Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Re: expect script aborting in the middle.

Posted by admin (Graham Ellis), 15 July 2007
Note to future readers ... the original poster has deleted his question ... which leaves this answer looking pretty daft! - I do wish people would think of other before they make changes that confuse the thread!

I think you're "send"ing before the incoming string has completed.  Rather than expect "word", try doing expect "word: " - otherwise you'll start sending the password before the telnet daemon is ready for it, loose the first few characters, resulting in an incorrect password being received and a host that won't let you log in.

P.S. You should do the same thing for the user name, though that may not be critical as you have type ahead buffering - but type ahead buffering rarely works with passwords.

Posted by manicisco (manicisco), 15 July 2007
sorry I had to remove my original post as it had the exact username and pwd and the IP address.Below is the more latest script per ur suggestion.But it didnt work.

package require Expect
set timeout 60
set username **
set password **
set target 172.21.x.x
spawn telnet $target
expect "name:"
exp_send "$username\r"
expect "Password:"  
exp_send "$password\r"
expect -re ">"
exp_send "show ip route\r"


User Access Verification

Username: xx
Password:

hostname removed>
C:\Tcl>

Appreciate ur time.


Posted by manicisco (manicisco), 15 July 2007
I also tried with

expect ">"

Posted by admin (Graham Ellis), 15 July 2007
I note that you've removed the training space off the end of my suggestion; does the password prompt that your system issues not have a space?  As I recall, your original post (which you have chosen to delete completely!) suggested it did.

Posted by manicisco (manicisco), 15 July 2007
I am sorry.i am new here,i didnt see the modify option.Ok let me write the problem description again.

My script.
*******
package require Expect
set timeout 60
set username removed
set password removed
set target x.x.x.x
spawn telnet $target
expect "name:"
exp_send "$username\r"
expect "Password:"  
exp_send "$password\r"
expect ">"
exp_send "show ip route\r"

Problem
******

Scirpt doesnt execute the "show ip route" command.It just exits out as soon as the password is being accepted.

User Access Verification

Username: xx
Password:

hostname>



Posted by manicisco (manicisco), 15 July 2007
Hi Graham,
                    I am not sure which space u r talking about.Is it the space before the password?

Posted by manicisco (manicisco), 16 July 2007
Graham,
                I just read ur posting on top.Sorry.I didnt mean to be selfish.I was so scared to see the username and pwd and the IP address on my post.So I removed the post immediately before seeing the modify option.

Posted by admin (Graham Ellis), 16 July 2007
on 07/15/07 at 22:34:57, manicisco wrote:
Hi Graham,
                    I am not sure which space u r talking about.Is it the space before the password?


Yes. The space that comes out after the prompt from your remote device, before you send the password back.   If you leave it out, you are having your expect program answer the request for the password before the host is ready for the response (and you might have to add in a delay as well, depending on how quickly the host turns around to receive the password).

Posted by manicisco (manicisco), 16 July 2007
Thanks for your time and help. A friend of mine helped me to come up with this script.It works fine.

package require Expect
set username xxx
set password xxxxx
set target x.x.x.x
spawn telnet $target
expect -re "name: "
exp_send "$username\r"
expect -re "Password: "  
exp_send "$password\r"
expect ">" {
     exp_send "terminal length 0\r"
     expect ">" {
     exp_send "show ip route\r"
     expect ">"
           exp_send "exit\r"
                }
}

Posted by admin (Graham Ellis), 16 July 2007
on 07/16/07 at 06:17:55, manicisco wrote:
Thanks for your time and help. A friend of mine helped me to come up with this script.It works fine.


I'm glad you're sorted, and glad to see that my suggestion / analysis was the correct one.

Posted by manicisco (manicisco), 16 July 2007
sure.thanks for ur time.Appreciate it.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho