无法在rpm安装脚本中从用户读取

时间:2015-06-03 10:52:48

标签: linux bash shell redhat rpmbuild

我创建了RPM Package,其中包含shell脚本代码,如下所示。当我在RedHat OS中安装它时,它没有接收用户输入并且不断循环。如果我手动运行同一个文件,它可以正常工作。如果有人知道请告诉我。

set +e 

IpAddress='0' 
condition=1    

while [[ $condition -ne 0 ]] 
do
    echo ' '   
    echo "PLEASE PROVIDE APPLIANCE IP" 
    read IpAddress   
    if valid_ip $IpAddress;   
    then
       condition=0   
    else
    echo $IpAddress  " IS INVALID IP PLEASE PROVIDE A VALID IP: " 
    echo ' '
    condition=1   
    f`enter code here`i 
done

condition=1 
while [[ $condition -ne 0 ]] 
do   
     echo "PLEASE PROVIDE APPLIANCE LOGIN PASSWORD"   
     read uiPassword   
     echo "The Password u entered is "$uiPassword   
     echo "Press Yes/No:"   
     read choice  
     choice=`echo $choice | tr '[:upper:]' '[:lower:]'`   
    case "$choice" in   
     yes|Yes ) condition=0;;   
     no|No ) echo "no";;   
     * ) echo "invalid";; 
    esac 
done

set -e

先谢谢

2 个答案:

答案 0 :(得分:1)

你有意无意; RPM不应该提示用户输入,因此RPM在运行钩子脚本之前关闭stdin。

但是,如果你想更努力(你不应该这样做!),然后打开/dev/tty以找到附加到你的控制TTY的过程:

if exec </dev/tty; then
  read IpAddress || {
    : "deal with the case where attempting to read from the user failed here"
  }
  # ...and use the information read here...
else
  : "deal with the case where you simply can't read from the user here"
fi

软件需要信息才能工作的最佳做​​法是要求将信息写入带外配置文件。

答案 1 :(得分:0)

我刚刚查找了有关处理RPM安装脚本上的用户输入的详细信息,我发现最广泛的共识是您不应该尝试获取用户输入。

典型的基本原理是从图形用户界面安装RPM,如here所述。

另外,我发现了这个相关的问题,其中&#34; no&#34;答案也出现了:https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm