Shell script calls sudo; how do I suppress the password prompt

前端 未结 5 840
萌比男神i
萌比男神i 2020-12-28 22:39

I am writing a simple shell script which changes the mac address of the network hardware. One of the line is :

sudo ifconfig eth0 hw ether 00:99:99:00:00:00
         


        
5条回答
  •  清酒与你
    2020-12-28 22:54

    Here is a Zenity dialog that does something similar to Tman's comment,
    though the password isn't stored in history... This may be a good alternative

    #!/bin/bash
    ENTRY=`zenity --password`
    case $? in
    0)
    pw=$(echo $ENTRY | cut -d'|' -f1)
    ;;
    1)
    echo "Stop login.";;
    -1)
    echo "An unexpected error has occurred.";;
    esac
    TMP=$(echo "${pw}" | sudo -Sv)
    TMP=0
    

提交回复
热议问题