I am trying to write a script that will be an extension attribute that will check if the system hostname (scuitl --get HostName) is the same as the hostname that pops up in system preferences (scutil --get ComputerName).
This is the Bash Script I have been messing with and if you run it you can see the echos will literally show that the outputs are the exact same. But yet the if statement says they are different.
What am I doing wrong? Am I using the wrong condition? Or are the variables actually different someway on the back end?
The script in question
var1=$(scutil --get ComputerName) var2=$(scutil --get HostName) echo $var1 echo $var2 if [ "$var1" == "$var2" ]; then echo same echo "<result>Same</result>" else echo different echo "<result>Different</result>" fi
The script I am using to change the hostname, in a policy, that will scope to a smart group set by the attribute of the above script.
#set variable to system prefrences name oldHostName=$(scutil --get HostName) spHostName=$(scutil --get LocalHostName) echo " System Prefrences Hostname is: $spHostName " echo " Current System Hostname is: $oldHostName "
change hostname system wide to LocalHostNameecho " Now setting sytem hostname to: $spHostName ... " sudo scutil --set HostName $spHostName echo "Done!" newHostName=$(scutil --get HostName) echo " System Hostname is now: $newHostName" echo " Now Exiting..." exit