script based on computer name

j99mac
Contributor

I am trying to run a script based on computer name
This is what I have so far

ComputerName=scutil --get ComputerName
if [[ "ComputerName" = MAC ]] then
echo""
fi

4 REPLIES 4

mm2270
Legendary Contributor III

First off, what's the purpose of the script? Just to echo the computer name back to you? I'm not sure what ypu're looking to accomplish with it.

Second, you need to do it as ```
if [ "$ComputerName" = "MAC" ]
```in the if/then block (note the $ to indicate its an assigned variable)

Third, if you're running this through a Casper Suite policy, you can also use $2 for the computer name, which Casper assigns automatically. But your scutil command is fine as is.

krichterjr
Contributor
Contributor

@mm2270
Since you were already on this post and you have been quite helpful in the past, I'm hoping you may be able to help.

I'm putting together a similar script/Extension Attribute to check the computer name to see if it has been changed. We use a prefix with the serial number of the computer.

I'm stuck on how to see if the computer name is = to the combined prefix and serial number.

if [[ "$computerName" = "MAC""$SN" ]]

Thanks in advance!

acdesigntech
Contributor II
if [[ "$computerName" = "MAC$SN" ]]

will output MAC1234567890 if 1234567890 was that Mac's serial number.

krichterjr
Contributor
Contributor

Thanks Andrew, I'll give that a try. I could have swore I used that at one point but I was making so many changes who knows.