How to delete a network profile from etc/wpa_supplicant/wpa_supplicant.conf through command line / shell script

后端 未结 4 1955
甜味超标
甜味超标 2021-01-03 07:20

I have multiple wifi network ssid\'s saved in my etc/wpa_supplicant/wpa_supplicant.conf like shown below, can we delete a specific network from this wpa_supplicant.conf

4条回答
  •  鱼传尺愫
    2021-01-03 08:08

    SSID=$1 
    temp_var=$(sudo awk -v RS= '!/${SSID}/{printf $0""RT}' etc/wpa_supplicant/wpa_supplicant.conf)
    echo -e "$temp_var" | sudo tee etc/wpa_supplicant/wpa_supplicant.conf
    

    The temp var is needed because this is the easiest way I found to actually make awk write to he file its processing. To see the effect of changing wpa_supplicant.conf, do

    svc wifi disable && svc wifi enable
    

    Some references:

    • https://stackoverflow.com/a/18955226/1246369
    • https://unix.stackexchange.com/a/89707/172003
    • http://ubuntuforums.org/showthread.php?t=981258#3

提交回复
热议问题