0

Using: CentOS 6.2 BASH shell

My script is something along the lines of

#!/bin/bash
INSTALL_PATH="Enter install path"
CR="\n"
/bin/su root -c "/usr/bin/expect << EOF
spawn name.run
expect $INSTALL_PATH
send $CR
EOF; ... do more stuff..."

Now sometimes my name.run file asks "Would you like to uninstall?" how can I send this as an optional argument after the first send?

1

1 Answer 1

3

You can put multiple patterns inside an expect command

spawn name.run
expect $INSTALL_PATH
send \r
expect {
  {Would you like to uninstall?} {
    send yes\r
    exp_continue 
  }
  eof 
}

Take note that you send "\r" to "hit enter".

Also, the terminal word for a here-doc must appear by itself on a line -- it cannot be followed by "; more stuff"

5
  • Cool, will try this out and get back to you if it works as I'm shooting for. Apr 17, 2012 at 2:21
  • I received a "invalid command name "/usr/bin/expect"... it seems like the EOF (see above) is being skipped with the conditional expect is ignored. Do I need to keep a second EOF after your closing brace?? Apr 21, 2012 at 0:29
  • 1
    the lower case eof I have in my answer is for expect. The upper case EOF in your question is for the shell to terminate the here-doc Apr 21, 2012 at 12:32
  • Ah, so in other words I need both, right? (The EOF for the here-doc and the eof for the embedded expect script, correct?) I really appreciate the help! Going to test it out now... Apr 21, 2012 at 22:38
  • WOOO! Once I added that EOF back in everything worked like a charm. Your conditional expect, combined with the timeout proofing of Niall Byrne made the script work perfectly.... unintendended CUDA install is working perfectly. :) Here's Byrne's post: stackoverflow.com/questions/10150939/… Apr 22, 2012 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .