3

I have a fleet of raspberry pi's running as access points. I set the default SSID and PASSWORD using a simple bash script that runs at boot. I get unique values for this:

SSID = cat /sys/class/net/wlan0/address | tail -c 10 | tr -d ":"

PW = cat /proc/cpuinfo | tail -c 9

I just echo the results on the hostapd file, everything work just fine, each Raspberry Pi get unique SSID and PW. Now I need to generate a JSON file with this values (via bash) in a format like this.

{
  "wifi": {
    "ssid": "SSID",
    "pw": "PW"
  }
}

Can anyone shed some light on this?

Regards

2
  • Depending on the size of your 'fleet' you might find that Ansible gives you a greater level of configuration control than bash scripts alone. Sep 11, 2017 at 14:53
  • Hey, Tom, thanks! This is for "LAB" only. We are using Resin.io to get it done, but for now i just need to give the dev team this json with ssid and pw. Sep 11, 2017 at 14:58

1 Answer 1

5

Heredocs perform variable expansion, so you can do something like

SSID=$(cat /sys/class/net/wlan0/address | tail -c 10 | tr -d ":")
PW=$(cat /proc/cpuinfo | tail -c 9)

cat >./config.json <<EOF
    {
      "wifi": {
          "ssid": "$SSID",
          "pw":   "$PW"
      }
    }
EOF
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.