http://blog.csdn.net/linhx/archive/2010/01/02/5118683.aspx
Linux中shell脚本运行时经常需要进行交互,比如安装软件的过程中对license声明的确认,需要输入yes,回车之类的确认信息。这个在自动化安装的时候就会是个问题。
通常对于这个问题比较灵活的解决方法就是TCL的Expect。但Expect还需要另外安装,平台通用性不高,比较麻烦。
另外一些简单的方法倒也是有,不过可用性不高,特别是对要求多次交互就吃力了。但怎么说其还是能解决大多数的问题,因为复杂的情况还是比较少的。比如要一个调用一个安装脚本 : , 这个脚本要求输入回车,则可以:echo | ;如果要求输入yes|no,加回车,则可以echo yes|. 这下自动化安装就有希望了。
再有一下的代码也可以带来一些思路:
[0 No.2015 huan@huan ~/tmp]$ cat foo
read -s -n1 -p "Press any key to continue ... "
echo "Your inputs: $REPLY"
[0 No.2016 huan@huan ~/tmp]$ ./foo < /dev/null
Your inputs:
[0 No.2017 huan@huan ~/tmp]$
-----------
# cat rug.sh #! /bin/bash set -x # update the package management stack first still needed??? if needed we need to adapt to sp3 update channel #rug in -y -t patch sledp2-libzypp sledp2-yast2-online-update-pkg-bindings #sleep 40 && rug ping -a # install all updates available for SP3: rug up -y --agree-to-third-party-licences -t patch <<EOF n EOF sleep 240 && rug ping -a # install the move-to-sles10-sp4 patch rug in -y --agree-to-third-party-licences -t patch move-to-sles10-sp4 sleep 40 && rug ping -a # bring the system to SP4 level: rug up -y --agree-to-third-party-licences -t patch <<EOF n EOF sleep 240 && rug ping -a rug unsub SLES10-SP4-Online # really needed??? You might want to remove the Online channel only if you did not use it on SP3 # install post-SP4 updates: rug up -y --agree-to-third-party-licences -t patch <<EOF n # For an automatic reboot after the migration, you may change 'n' to 'y' EOF
















