LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2014, 04:48 PM   #1
ktfreak
LQ Newbie
 
Registered: Nov 2010
Posts: 16

Rep: Reputation: 0
Expect problem: capturing prompt line


Hi,

I wrote an Expect script which logs-in to a remote host then walks through a command list file and sends commands to the remote host step by step. Between two commands the script waits for the remote prompt and then proceeds with the next command. The script actually works fine so far, but sometimes the prompt string is not unique enough so that the script finds the remote prompt string within the actual output data and proceeds with the next command erroneously. I found this interesting article here which explains the problem a little bit more detailed: http://linuxgazette.net/2013/01/adva...t-your-prompts

The remote host is a cisco switch and the prompt string can be for example "MyCoolCiscoSwitch#". It begins with a variable part - mostly the hostname - and ends with an "#" sign. I'm using the regular expression "(.*#$)" but it's still not unique enough.
Anyway...

My actual question is how can I catch the line that seems to contain my remote prompt string?

I'm thinking of something similar like this

expect {
-re "(.*#$)" {
puts "remote prompt string found in this line " [a damned cool function which shows the last captured line]
}
}

I need this for debugging purposes. It would be very helpful to see the line which causes my script to behave erroneous.

Thanks,
 
Old 03-31-2014, 11:17 AM   #2
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
built-in debugging

what language are you writing the script in?

i was thinking if it is a bash script you could try running it with the built in debugger to see if this satisfies your debugging needs?

Code:
# bash -x YOUR_SCRIPT
-v will give you the lines as they are read


http://tldp.org/LDP/Bash-Beginners-G...ect_02_03.html

Last edited by cin_; 03-31-2014 at 11:22 AM. Reason: gramm`err
 
Old 03-31-2014, 08:13 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,973

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
Might try it again with autoexpect? See if that fixes it. Then compare scripts.
 
Old 03-31-2014, 09:54 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
At the very start of you expect script put:
Code:
exp_internal 1
(right on the next line after the opening curly brace)
You'll see exactly which strings are matched and why

jlinkels
 
Old 04-08-2014, 12:04 PM   #5
ktfreak
LQ Newbie
 
Registered: Nov 2010
Posts: 16

Original Poster
Rep: Reputation: 0
The script is written in "Expect" which is based on TCL.

I'll try the built-in debugger, good idea...
 
Old 04-08-2014, 12:39 PM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by ktfreak View Post
I'll try the built-in debugger, good idea...
The "built-in" debugger will only show you that bash calls Expect.
It doesn't show anything happening within Expect.

jlinkels
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsh autocompletion problem with multi-line prompt nitnelave Linux - Software 0 10-11-2013 12:45 AM
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 04:29 AM
Capturing Print Screen from command Prompt and Saving automatically to Clipboard kiratjohal Linux - Member Desktop Screenshots 1 09-07-2011 07:00 PM
expect: line seems to match exactly, however expect thinks not deadeyes Linux - General 5 06-16-2010 06:05 PM
problem with command line prompt ??? robeb Linux - General 2 12-07-2002 08:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:26 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