Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
also asked on stackoverflow -- stackoverflow.com/q/10150939/7552 –  glenn jackman Apr 14 '12 at 10:49
add comment

1 Answer

up vote 1 down vote accepted

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"

share|improve this answer
    
Cool, will try this out and get back to you if it works as I'm shooting for. –  Jason R. Mick Apr 17 '12 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?? –  Jason R. Mick Apr 21 '12 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 –  glenn jackman Apr 21 '12 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... –  Jason R. Mick Apr 21 '12 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/… –  Jason R. Mick Apr 22 '12 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.