简体   繁体   中英

Can you sudo with input whiptail?

I want to ask your sudo password with whiptail password and then use it to run sudo script.sh this is possible?

I have tried this sudo command with the whiptail input for password

sudo -S <<< $psw script.sh

echo $ psw | sudo -S

Full Code

#!/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

A quick check shows the script should work (works for me). Your script is calling sudo separately from whiptail , so the two are not interfering with each other's use of the terminal.

The script should begin with

#!/bin/bash

because it uses the here-string

<<< $psw

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM