18541

automating install.sh script using an expect script

Question:

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.

<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>

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.

Answer1:

#!/bin/bash ....... ....... expect -c " spawn ./install.sh expect \"Install the 5.1.0 package\? \(Q\|Y\|N\) \[Y\]\: \" send \"Y\r\" interact " ....... .......

Answer2:

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

Recommend

  • RegEx to split string based on operators and retain operator in answer
  • MYSQL, using unique table names VS using ids
  • Element style not allowed as child of element body in this context ( not validating)
  • Working with Bluetooth in android kernel development linux
  • View Animation (Resizing a Ball)
  • Connect my Activity, Service and BroadcastListener
  • How can using cooperative groups feature of CUDA in windows
  • Python multiprocessing: understanding logic behind `chunksize`
  • python multiprocess update dictionary synchronously
  • tag partial tree vs full trunk in svn
  • Convenient access to members of raw pointers?
  • How to parse a text file in tcl using separators?
  • Threads have almost no overhead; processes have considerable overhead. What does it mean? [closed]
  • How can my Java program be used to open a file when the file is double clicked? [closed]
  • expect telnet to multiple cisco devices and execute show run
  • Transfer data from Windows Service to Console Application repeatedly
  • Using if/else in expect script
  • Inter change blue and red channels in bitmap in android
  • could not able to spawn(ssh) using expect
  • Chaining multiple async functions in Swift
  • How do I put a semicolon in a value in python configparser?
  • What is lua_len() alternative in Lua 5.1?
  • Development workflow for server and client using Docker Compose?
  • Call a macro with parameters : Python win32com API
  • How to debug Shell command after customization
  • Getting short path in python
  • How to read piped content in C?
  • cygwin cannot exec 'git-add--interactive' permission denied
  • How to assign byte[] as a pointer in C#
  • Unable to install Git-core+svn by MacPorts
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • Django simple Captcha “No module named fields” error
  • Do I need to reset a Perl hash index?
  • Could not find rake using whenever rails
  • javascript inside java/jsp code
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory