gpt4 book ai didi

linux - 首次 root 登录读取问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:26:24 24 4
gpt4 key购买 nike

我想执行的脚本主要是询问用户一个问题,并根据用户的输入配置自定义应用程序的值。问题是它被执行但不提示用户输入并采用默认值。

我已经从 root 用户的 bashrc 中调用了脚本,如下所示

if [ -e /opt/services_vm/autoUpgrade.sh ];
then
/opt/services_vm/autoUpgrade.sh
fi

自动升级脚本如下所示

#!/bin/bash

while true; do
read -p "Do you want to enable automatic upgrade [Y|y - Yes] [N|n - No] [Yes] ?" yn
case $yn in
[Yy] | "" ) sed -i "s#<autoupgrade-enabled>OFF<\/autoupgrade-enabled>#<autoupgrade-enabled>ON<\/autoupgrade-enabled>#g" /opt/avaya/SAL/gateway/SpiritAgent/config/agent/SPIRITAgent_1_0_PDComponentConfig.xml;
rm -rf /opt/services_vm/autoUpgrade.sh
exit;;
[Nn] ) rm -rf /opt/services_vm/autoUpgrade.sh
exit;;
* ) echo "Please answer yes or no.";;
esac
done

问题是它没有提示用户输入,并且默认情况下会执行第一个 case 语句。我可以在日志中看到这一点。此外,root 用户必须根据我所做的配置更改第一次尝试时的传递。它强制用户更改密码并执行以下脚本,但采用默认输入而不是提示用户。

最佳答案

我按如下方式尝试了您的脚本,将其放入 .bashrc 中,它按预期工作。它提示并且答案被付诸行动(它回应正确的词)。先试试看。我觉得问题不在于您的脚本。

#!/bin/bash

while true; do
read -p "Do you want to enable automatic upgrade [Y|y - Yes] [N|n - No] [Yes] ?" yn
case $yn in
[Yy] | "" ) echo YES;
exit;;
[Nn] ) echo NO;
exit;;
* ) echo "Please answer yes or no.";;
esac
done

关于linux - 首次 root 登录读取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44502388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com