Skip to main content
Question

script based on computer name


Forum|alt.badge.img+8

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

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • July 30, 2012

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.


Forum|alt.badge.img+12
  • Employee
  • 128 replies
  • April 5, 2013

@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!


Forum|alt.badge.img+12
  • Contributor
  • 417 replies
  • April 5, 2013
if [[ "$computerName" = "MAC$SN" ]]

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


Forum|alt.badge.img+12
  • Employee
  • 128 replies
  • April 6, 2013

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings