问题
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
Thanks in Advance
回答1:
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.
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.
回答2:
I just looked for details on handling user input on RPM installation scripts and the widest consensus I can find is that you should not try to get user input.
Typical rationale is the case of installing RPMs from a graphical UI, as described here.
Also, I found this related question where the "no" answer also appears: https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm
来源:https://stackoverflow.com/questions/30618014/unable-to-read-from-user-in-rpm-install-script