自动使用expect脚本install.sh脚本 [英] automating install.sh script using an expect script

查看:253
本文介绍了自动使用expect脚本install.sh脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点,我似乎无法找出一个困惑,我敢肯定,这很容易。

我有一个外部的shell脚本,我们将其称之为用来安装一块,我们公司开发的软件install.sh。我想用自动期待(与外部参数)的install.sh的过程,因为它是pretty便于模式匹配的输出字符串和传递一堆参数,无论是作为一个数组或参数的expect脚本。

不幸的是,许多在线的例子是SCP或FTP,没有这些都对我有意思,因为我想要自动执行一个简单的安装脚本,而不是那些互动炮弹,而不是剧本。

下面是一个简单的期待,我试图创建一个示例脚本:

 #!的/ usr / bin中/预期
#传递的参数
设置domPassw [LINDEX $ ARGV 1]
设置JOINDOMAIN [LINDEX $ ARGV 2]
设置cdcVersion [LINDEX $ ARGV 3]
设置domUser [LINDEX $ ARGV 4]#在CD
CD /Users/wqcoleman/Desktop/suite-mac10.6/;#开始安装
产卵运行./install.sh#第一场比赛
预计安装5.1.0包(Q | Y | N)[Y]:?
发送Y \\ R

我敢肯定,我可以弄巧在这里和bash脚本之内做到这一点,但是这是很难就我而言,我宁愿有一个简单的迭代脚本匹配的输出,并发送一个输入,看来简单的我。

我有两个基本问题。


  1. 在当前正上方,然后运行,它似乎并没有火了
    运行./install.sh脚本。什么也没有?什么搭配?没有什么是
    输出。

  2. 我需要运行运行./install.sh脚本根目录,
    当我最初开始这一点,我想产卵会有些
    架空的开始,但它没有,所以我不知道如何在这里做到这一点。

我要运行是这样的:

 #!/斌/庆典
#询问管理员密码前期
须藤-v#保持活动:更新现有`sudo`时间戳,直到`.update`完成
而真实的;做须藤-n真实的;睡60;杀-0$$||出口;做了2 - ;的/ dev / null的&安培;#在CD
CD /Users/wqcoleman/Desktop/suite-mac10.6/;#开始安装
产卵运行./install.sh

和再擀成期望的,但没有在所有的工作..所以我不知道从哪里开始,写一个bash脚本,并呼吁期待内部?或者写一个expect脚本,并调用升高提示里面的install.sh?

任何建议将是最有帮助的。


解决方案

 #!/斌/庆典
.......
.......
预计-c
产卵运行./install.sh
预计\\安装5.1.0包装\\ \\(Q \\ | Y \\ | N \\)\\ [Y \\] \\:\\
发送\\Y \\ r \\
相互作用
.......
.......

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.

  1. When running then above, it doesn't seem to "fire" the ./install.sh script. There is nothing? nothing to match? nothing is outputted.
  2. 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.

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.

解决方案

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

这篇关于自动使用expect脚本install.sh脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆