在rpm安装脚本中无法从用户读取 [英] Unable to read from user in rpm install script

查看:61
本文介绍了在rpm安装脚本中无法从用户读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了RPM软件包,其中包含如下所示的shell脚本代码.当我在RedHat OS中安装它时,它并没有接受用户输入并不断循环.如果我手动运行同一文件,则可以正常工作.如果有人知道,请让我知道.

I've Created RPM Package which contains shell script code which shown below. When I'm installing it in RedHat OS, It is not taking user input and continuously looping. If I run the same file manually it's working fine. If Anybody Knows Please let me know.

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

预先感谢

推荐答案

您故意不能这样做;RPM不应提示用户输入,因此,RPM在运行钩子脚本之前关闭stdin.

It's intentional that you can't; RPMs shouldn't prompt for user input, and for that reason, RPM closes stdin before running hook scripts.

但是,如果您想更加努力(您不应该这样做),请打开/dev/tty 来查找与控制TTY关联的进程:

However, if you want to try harder (which you shouldn't!), then open /dev/tty to find the process attached to your controlling 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


当软件需要信息才能正常工作时的最佳实践是要求将信息带外写入配置文件中.


Best practice when software needs information before it can work is to require that information to be written to a configuration file out-of-band.

这篇关于在rpm安装脚本中无法从用户读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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