你可以用输入whiptail sudo吗?

时间:2015-11-11 23:57:04

标签: linux bash debian whiptail

我想用whiptail密码问你的sudo密码然后用它来运行sudo script.sh这可能吗?

我尝试过这个sudo命令,输入密码为

的whiptail
sudo -S <<< $psw script.sh

echo $ psw | sudo -S

完整代码

#!/bin/bash

#Password Input
    psw=$(whiptail --title "Test Password Box" --passwordbox "Enter your password and choose Ok to continue." 10 60 3>&1 1>&2 2>&3)
    #Password If
    exitstatus=$?
    if [ $exitstatus = 0 ]; then
        sudo -S <<< $psw script.sh
    else
        #Password If cancel
        whiptail --title "Cancel" --msgbox "Operation Cancel" 10 60
    fi

1 个答案:

答案 0 :(得分:1)

快速检查显示脚本应该有效(适合我)。您的脚本与sudo分开致电whiptail,因此两者不会干扰彼此对终端的使用。

脚本应以

开头
#!/bin/bash

因为它使用here-string

<<< $psw