Ubuntu – sudo command and how to auto get password


I got a problem that:

I have a file .sh


var=$(zenity --forms --title="Tắt giờ vợ yêu nhé" \
    --text="Vợ muốn tắt máy sau bao nhiêu phút nữa" \
    --separator="," \
    --add-entry="Vợ điền số vào đây")
case $? in
    0)  sudo shutdown -h $var           
        exit 0;;
        echo "An unexpected error has occurred."

How can sudo command autofill the password from echo command or a file.
I read about sudo -S options, but i dont know how it works.
Anyone can give an example about it!
Thanks guys

Best Answer

It's better to change sudo rules instead storing clear password in a text file :

Create a new file like /etc/sudoers.d/script_rights and push

%user ALL = NOPASSWD:/sbin/shutdown

where user is the user allow to run the script.sh. Then the script will not ask the password to run the shutdown command.