Reputation: 145
I have a bit of a quandary that I can't seem to figure out, and i'm sure it's easy..
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.
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".
Here is an example of a simple expect script that I'm trying to create:
# !/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"
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.
I have two basic questions.
I was going to run something like this:
#!/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>/dev/null &
# cd over
cd /Users/wqcoleman/Desktop/suite-mac10.6/;
# start install
spawn ./install.sh
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?
Any suggestions would be most helpful.
Upvotes: 1
Views: 5316
Reputation: 247062
Rather than focus on the expect script, you might get better help showing what inputs the install script requires. The solution might be as simple as providing the responses to install.sh on its stdin:
install.sh << END_OF_RESPONSES
Y
answer1
answer2
answer3
END_OF_RESPONSES
Upvotes: 1
Reputation: 3880
#!/bin/bash
.......
.......
expect -c "
spawn ./install.sh
expect \"Install the 5.1.0 package\? \(Q\|Y\|N\) \[Y\]\: \"
send \"Y\r\"
interact "
.......
.......
Upvotes: 3