EA to look for a specific network in the preferred list

GabeShack
Valued Contributor III

Hey all,
We are having an issue where an 802.11x network we push in a profile is getting removed from the preferred list of networks and then it breaks the profiles ability to join said network.

My solution to this is to find all the devices that are missing that network and then exclude, then re scope them to that profile, but I need some help with the scripting of the EA.

We have 3 networks all named similar. Each includes the name or our district so its making it hard for me to grep the exact network I need from the list without pulling all 3 of them. Then I just need a result that said" has the network" or "doesn't have the network". Two things not working is the grep for the specific network name and the if section if the result is blank.
Any help would be greatly appreciated!

Here is what I have so far:

#!/bin/sh

##Get the wireless port ID
WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')

##Collect new preferred wireless network inventory and send back to the JSS
PreferredNetworks=$(networksetup -listpreferredwirelessnetworks "$WirelessPort" | sed 's/^   //g' | grep -w "Princeton Schools")
if ["$PreferredNetworks" == "" ]; then echo "<result>NeedsPrincetonSchools</result>"
else echo "<result>Has Princeton Schools</result>"
fi

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools
1 ACCEPTED SOLUTION

GabeShack
Valued Contributor III

Looks like I cobbled together something a little different that does what I was looking for:

#!/bin/bash
SSIDNAME=$"YourSSIDHere"

NETFILE="/Library/Preferences/
SystemConfiguration/com.apple.airport.preferences.plist"

#Get SSID for desired network
SSIDID=`xpath $NETFILE "
(//dict/dict/dict/string[text()='$SSIDNAME'])
[1]/parent::dict/preceding-sibling::key[1]" 
2>/dev/null | sed -e 's/key/string/g'`

# Make sure the desired SSID exists in the list.
if [ -z "$SSIDID" ]; then
 echo "<result>Missing YourSSIDHere</result>"; else

echo "<result>Has YourSSIDHere</results>"

fi

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

View solution in original post

1 REPLY 1

GabeShack
Valued Contributor III

Looks like I cobbled together something a little different that does what I was looking for:

#!/bin/bash
SSIDNAME=$"YourSSIDHere"

NETFILE="/Library/Preferences/
SystemConfiguration/com.apple.airport.preferences.plist"

#Get SSID for desired network
SSIDID=`xpath $NETFILE "
(//dict/dict/dict/string[text()='$SSIDNAME'])
[1]/parent::dict/preceding-sibling::key[1]" 
2>/dev/null | sed -e 's/key/string/g'`

# Make sure the desired SSID exists in the list.
if [ -z "$SSIDID" ]; then
 echo "<result>Missing YourSSIDHere</result>"; else

echo "<result>Has YourSSIDHere</results>"

fi

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools