LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-02-2012, 04:08 AM   #1
piercazzo
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
expect - multiple lines


Hi, I'm trying to automate access to a switch with expect.
What happens is that login is successful but after login the switch sends to the terminal a message

Enable privilege granted.

switch1#
Aug 2 10:58:05 switch1 NOTICE mgmt: user(admin) login from host 123.123.123.123



So I should expect 5 lines: the first matches "Enable privilege granted", then a blank line, then "switch1#", then the long message, and finally an empty line where the curor blinks.

I tried to match any sort of characters, but I suspect that the culprit is the last empty line.
The outcome is that either the script times out because it matches nothing or that it exits.
Any suggestion?
I attach one of the many versions of the script.
Pier


#!/usr/bin/expect
#exp_internal 1
spawn telnet 10.2.3.4
expect "Enter tacacs username:"
send "user\r"
expect "Enter tacacs password:"
send "password\r"
expect "#"
send "sh run\r"
send " "
exit
 
Old 08-02-2012, 05:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what problem do you actually have here? Generally your 'expect "#"' should do the trick. Note that if you "send" and then do NOT "expect" another prompt after it, the script will exit immediately, and you'll not see the consequences of your "send"
 
Old 08-02-2012, 07:02 AM   #3
piercazzo
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Geez, it was that simple! I added another expect "#" after the show run and that worked!
Thanks!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Make multiple blank lines to a single lines kimhj3715 Programming 5 06-10-2012 10:35 AM
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 06:09 AM
[SOLVED] Help with expect command and multiple arguements genderbender Programming 3 10-04-2010 07:26 AM
[SOLVED] expect help (multiple commands in argument) vikas027 Programming 10 03-17-2010 01:19 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration