Hello All,
This is probably a simple one, but I'm pretty new to bash scripting..
I created an EA to compare a computer's JSS record and AD to ensure there aren't any mismatches. This works properly when the names match and returns a mismatch if the dsconfigad commands returns something that doesn't matches. However, the problem is that if the machine isn't bound to AD, this still returns a match. I tried doing a null string test, but still NG...
#!/bin/bash
jssName=`jamf getComputerName | awk '{print tolower($0)}'`
adinfo=`dsconfigad -show | grep 'Computer Account' && dsconfigad -show | grep 'Active Directory Domain'`
computerName=`scutil --get ComputerName`
if [[ $adinfo = *"${jssname}"* ]];
then
echo "<result>JSS & AD records match.
JSS Record = $computerName
$adinfo</result>"
elif [ -z $adinfo ];
then
echo "<result>Not bound to AD...attempting to rebind. If this isn't auto-corrected in about 15 minutes, I'll need to be connected to the LAN to be fixed.</result>"
else
echo "<result>Mismatch.... help please!
JSS Record = $jssName"
if [ -z $adinfo ];
then
echo "I'm not bound to AD either! This should be fixed shortly, though</result>"
else
echo "$adinfo</result>"
fi
fi
Just a little background on why this is needed -- we're using DEP to initially enroll Macs as their serial number, then manually renaming in the JSS later during initial setup. This then triggers a policy to unbind the computer, remove the dummy AD record and rebind it under our naming convention.
