Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect script with ESC commands

Status
Not open for further replies.

NotBear

Programmer
Jun 22, 2003
11
AU
Hi,
I am trying to write an expect script to automate an interactive terminal logon. However, some of the commands I want to use on the terminal include the ESC key, eg. ESC-x, ESC-e. How can I put these ESC commands into my script, using either substitute characters or a replacement for the ESC key ?
 
vi <file>
go to the place you want the <ESC> character and type 'i^V<ESC><ESC>'

where ^V is <cntrl>-v

meaning i <insert>
^V <literal next character>
<ESC> <insert escape char>
<ESC> finish inserting
 
Informational: Use exp_internal 1 to see what expect
sees, then you will easily be able to use the right
pattern for any of your keystroke shortcuts.

In your case this simple script should illustrate the point.

Code:
#!/usr/bin/expect
##escape test
#exp_internal 1
set prompt &quot;.*@.*&quot;
set escseq &quot;\u001b&quot;
set timeout 100
spawn /bin/sh

           expect {
                 -re &quot;$prompt&quot; {
                               send_user &quot;Logged in..\r\n&quot;
                               interact {
                                  -re &quot;$escseq&quot; {send_user &quot;Escape detected\r\n&quot;}
                                   &quot;quit&quot; {send_user &quot;Exiting...&quot; ; inter_return}
                               }
                 }
               eof {send_user &quot;Shell died????\n&quot;}
               timeout {send_user &quot;Too much waiting on $prompt, seeya\n&quot;}
            }

Using exp_internal 1, I identified the esc key code sent
as \u001b.
YMMV.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top