title: automating install.sh script using an expect script
body: <p>I have a bit of a quandary that I can't seem to figure out, and i'm sure it's easy..</p>
  
  <p>I have an external shell script, we will call it "install.sh" that is used to install a piece of software that our company develops.  I want to automate that install.sh process using expect (with external arguments), since it's pretty easy to pattern match on the output strings and pass in a bunch of arguments, either as an array or arguments to the expect script.  </p>
  
  <p>Unfortunately, many of the examples online are for "scp" or "ftp" and none of these are interesting to me, since I'm trying to automate a simple install script, and not those interactive shells, but not a "script".</p>
  
  <p>Here is an example of a simple expect script that I'm trying to create:</p>
  
  <pre><code># !/usr/bin/expect
  # passed arguments
  set domPassw [lindex $argv 1]
  set joinDomain [lindex $argv 2]
  set cdcVersion [lindex $argv 3]
  set domUser [lindex $argv 4]
  
  # cd over
  cd /Users/wqcoleman/Desktop/suite-mac10.6/;
  
  # start install
  spawn ./install.sh
  
  # first match
  expect "Install the 5.1.0 package? (Q|Y|N) [Y]:"
  send "Y\r"
  </code></pre>
  
  <p>I'm sure I could get clever here and do this within a bash script, but this is harder as far as I'm concerned and I would rather have a simple iterative script that "matches" the output and sends an input, it seems simpler to me.</p>
  
  <p>I have two basic questions.</p>
  
  <ol>
  <li>When running then above, it doesn't seem to "fire" the
  ./install.sh script.  There is nothing? nothing to match? nothing is
  outputted. </li>
  <li>I need to run the ./install.sh script as root, and
  when I initially started this, I figure spawn would have some
  "elevated" start, it doesn't, so I have no idea how to do this here.</li>
  </ol>
  
  <p>I was going to run something like this:</p>
  
  <pre><code>#!/bin/bash
  # Ask for the administrator password upfront
  sudo -v
  
  # Keep-alive: update existing `sudo` time stamp until `.update` has finished
  while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2&gt;/dev/null &amp;
  
  # cd over
  cd /Users/wqcoleman/Desktop/suite-mac10.6/;
  
  # start install
  spawn ./install.sh
  </code></pre>
  
  <p>and then roll into expect, but that didn't work AT ALL.. so I'm not sure where to start, write a bash script and call expect inside? or write an expect script and call the install.sh with elevated prompt inside that?  </p>
  
  <p>Any suggestions would be most helpful.  </p>