2
I'm currently writing a shell-script for my Raspberry Pi so it sets up an access-point with a unique SSID. To do this I want to use the mac-address of the WiFi dongle as my SSID. For doing that I want to use awk, with
awk '{ gsub(/:/, ""); print > "file" }' /sys/class/net/wlan0/address
I can write the properly formatted mac address to a file, but how can I insert it into a specific line/place at another file? I have in mind something like
awk '{ gsub(/:/, ""); "replace ssid= at /etc/hostapd/hostapd.conf" }' /sys/class/net/wlan0/address
Any help plus explanation for a newbie like me is appreciated.
My input file is like:
$ cat /sys/class/net/wlan0/address
01:23:45:67:89:ab
and I'm trying to fetch it and replace the value of ssid
in the file which is like:
interface=wlan0 driver=nl80211 ssid=7cdd907f6b07 hw_mode=g channel=11 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=1 wpa_passphrase=My_Passphrase wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Can you paste some example content of /sys/class/net/wlan0/address to parse? And what are you expected results? – kenorb – 2015-10-26T23:54:34.423
@kenorb the content is a mac address:
7c:dd:90:7f:6b:07
and the expected results aressid=pi_7cdd907f6b07
within the/etc/hostapd/hostapd.conf
– Jabaal – 2015-10-27T09:46:45.910Just single line with something like
01:23:45:67:89:ab
? Can you simply usegrep
:grep -o ..:..:..:..:..:.. >> file
? Or the issue is rather that you want it at the particular line? Do you haveex
in Rasberry Pi? – kenorb – 2015-10-27T09:50:39.247I have multiple lines within the
/etc/hostapd/hostapd.conf
- I just need to modify the one withssid=some_ssid
- thegrep
command just writes to a file. – Jabaal – 2015-10-27T09:52:03.277