I think it could be handy to have a class in cfengine that tells us something about the ESSID of the wireless network we are connected to. Unfortunately, cfengine doesn't define one by default, and I thought it could be a good idea to make a module for that. It has been buzzing in my head for a while, and tonight I took some 30 minutes to make it happen.
On Linux, we have the command iwgetid that tells us the ESSID of the wireless networks we are connected to. However, ESSIDs may contain characters that are not allowed in a class name, so we need to "escape" them. The following, tiny bash script reads the output of iwgetid and returns the corresponding class names to be defined:
#!/bin/bash PATH="/sbin:/usr/sbin:/usr/bin:/bin" for ESSID in $( iwgetid --raw ) do CESSID=$( echo $ESSID | tr -c "a-zA-Z0-9_" "_" | sed -e 's/_*$//' ) CLASS="essid_${CESSID}" echo "+${CLASS}" done exit 0
On the laptop I am currently using, it returns:
root@cooper:/var/cfengine/inputs# modules/essid.sh +essid_WiFiOslo
And here it is! When we use this script as a module in cfengine, it will define a class named essid_WiFiOslo.
For more information about cfengine's module protocol, see the reference.