Results 1 to 2 of 2
I'm writing a bash script to automate a whole bunch of installation steps that i do quite regularly and have run into an issue. When I come across a prompt ...
- 04-28-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 9
Using Expect to mimic keyboard input
I'm writing a bash script to automate a whole bunch of installation steps that i do quite regularly and have run into an issue. When I come across a prompt such as "Continue with installation (y/n)?" I want the script to automatically reply with y [return]. I've been told that expect can do this quite easily but i'm having a really hard time understanding it. Heres the gist of what I've been trying so far:
#!/usr/bin/expect
spawn (process, removed for proprietary reasons)
expect "Continue with installation (y/n)?"
send "y\r"
I've tried many variations of this and either it keeps spawning the process over and over and never gets to the prompt or it just sits at the prompt and never sends the y[return]. Any help or links to simple examples of expect scripts would be helpful.
- 04-29-2011 #2Just Joined!
- Join Date
- Apr 2011
- Posts
- 9
I've gotten slightly farther
Okay, after quite a bit of banging my head against the wall I have partially figured out the problem.
Expect also requires hidden characters for the "expect" command. After using notepad++ to examine the prompt i'm trying to reply to, there is a [CR] (carriage return) and [LF] (linefeed) following the line i am trying to reply to.
[CR] is represented by ctrl+m and [LF] is represented by ctrl+j but i'm not sure how to signify that in bash. I'll be working on that tomorrow and post here if i do for anyone searching, but it would be nice to wake up and have an answer at my fingertips


Reply With Quote