【问题标题】:Script not recognizing sudo password and fails脚本无法识别 sudo 密码并失败
【发布时间】:2020-06-12 19:03:30
【问题描述】:

所以我有这个运行 sudo apt-get upgrade 并自动更新的小脚本(即使我想升级或不升级也会回答),但是当我通过 ./sync.sh 运行它时,它会提示我输入密码,即使我将其声明到脚本中。

有人知道怎么回事吗?

sync.sh

#Colors
green=$(tput setaf 2)
normal=$(tput sgr0)

clear
echo password | yes | sudo -S apt-get upgrade

echo "${green}-------- APT-GET UPGRADE DONE --------${normal}"

echo password | yes | sudo -S apt-get update

echo "${green}-------- APT-GET UPDATE DONE ---------${normal}"

输出如下:

Sorry, try again.
Sorry, try again.
Sorry, try again.
sudo: 3 incorrect password attempts
-------- APT-GET UPGRADE DONE --------
Sorry, try again.
Sorry, try again.
Sorry, try again.
sudo: 3 incorrect password attempts
-------- APT-GET UPDATE DONE --------

【问题讨论】:

  • echo password | sudo -S apt-get -y upgradesudo -S apt-get -y upgrade <<< password ?

标签: bash ubuntu root sudo chmod


【解决方案1】:

问题可能在于echo password | yes 永远返回

y
y
y

尝试使用xargs:

echo password | xargs yes

或者只是yes 没有管道

yes password

【讨论】:

    猜你喜欢
    • 2019-12-30
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多