Uncategorized

Serial Numbers Reprise (this time for hard drives)

Having to hack away at a strange request, getting the serial numbers for the hard drives installed on a system.

First, for the shell script for the Macs (tested on 10.8 and 10.9).
ioreg -c IOAHCIBlockStorageDevice | grep "Device Characteristics" | awk -F "Serial Number\"" '{print $2}' | awk -F "\"" '{print $2}'

Next for you windows folks, a quick one-two in the powershell.
wmic path win32_diskdrive get SerialNumber

’till next time.
Advertisements

Can a Mac run 10.9 or 10.8

Casper Extension Attributes (BASH Shell Scripts) to know if a Mac can be downgraded.

This is something that came up when we were forced to do downgrades to Macs coming in the Mavericks, since the 10.9 image wasn’t officially tested yet we could not release it to the wild. Some machines were okay, some were not. While the immediate need for this has passed, I did write this up so I could modify it for the next OS. These are not 100% accurate, as Apple changes the contents of a model and will not increment the model number (they did this with Mavericks and the MBP’s recently).

But this gives us a starting point.  Both for finding out what machines can run the OS, and for what machines can not.

To update the list (for 10.10 or X2 or 11.00) you will have to use MacTracker or something similar to find the minimal specs for the OS, then get the model number for each, replacing the minimum value in each.  I then took the a look through each model and found the model number that shipped with 10.9 and marked the one under that as the last version of the model that would run the older OS.

Extension Attribute to Check for Mavericks (10.9) Compatibility

#!/bin/bash

## Checks to see if Machine is compatible with Mac OS 10.9

hw_model=`sysctl hw.model | awk '{ print $2 }'`

mod_name=`echo $hw_model | tr -cd [[:alpha:]]`
mod_majver=`echo $hw_model | awk -F "," '{ print $1 }' | tr -cd [[:digit:]]`
mod_minver=`echo $hw_model | awk -F "," '{ print $2 }'`


## Find Machine And Report Back

case "$mod_name" in 
 iMac* )
 if [[ $mod_majver -ge 7 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBookPro* )
 if [[ $mod_majver -ge 5 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 Xserve* )
 if [[ $mod_majver -ge 3 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBookAir* )
 if [[ $mod_majver -ge 2 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 Macmini* )
 if [[ $mod_majver -ge 3 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacPro* )
 if [[ $mod_majver -ge 3 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBook* )
 if [[ $mod_majver -ge 5 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 * )
 echo "<result>Error</result>"
 ;;
esac

exit 0

Extension Attribute for testing Mt. Lion (10.8) compatibility.

#!/bin/bash

## Checks to see if Machine is compatible with Mac OS 10.8
hw_model=`sysctl hw.model | awk '{ print $2 }'`

mod_name=`echo $hw_model | tr -cd [[:alpha:]]`
mod_majver=`echo $hw_model | awk -F "," '{ print $1 }' | tr -cd [[:digit:]]`
mod_minver=`echo $hw_model | awk -F "," '{ print $2 }'`

## Find Machine And Report Back
case "$mod_name" in 
 iMac* )
 echo "iMac"
 if [[ $mod_majver -ge 7 ]] && [[ $mod_majver -lt 15 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBookPro* )
 echo "MBP"
 if [[ $mod_majver -ge 5 ]] && [[ $mod_majver -lt 11 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 Xserve* )
 echo "XS"
 if [[ $mod_majver -ge 3 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBookAir* )
 echo "MBA"
 if [[ $mod_majver -ge 2 ]] && [[ $mod_majver -lt 7 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 Macmini* )
 echo "Mm"
 if [[ $mod_majver -ge 3 ]] && [[ $mod_majver -lt 7 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacPro* )
 echo "MP"
 if [[ $mod_majver -ge 3 ]] && [[ $mod_majver -lt 6 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi
 ;;
 MacBook* )
 echo "MB"
 if [[ $mod_majver -ge 5 ]]; then
 echo "<result>Compatible</result>"
 else
 echo "<result>Not Compatible</result>"
 fi

 ;;
 * )
 echo "<result>Error</result>"
 ;;
esac
exit 0

’till next time.

Turn off Wi-Fi via shell script

Need to send a Shell Script to disable the wi-fi network?  No problem!  Have multiple types of machines that may have different device ID’s for the wi-fi?  No problem!

#!/bin/bash

# By Chris
## This will send a power-down to the Wi-Fi Device.
## Tested on 10.8.2 with single Wi-Fi device/hardware.

## First we get the Wi-Fi device name.  We are not assuming it is en1.
# We do this by listing all the hardware on the device, then only showing the line of and immediately following "Wi-Fi".
# Then do a quick second grep to only show the line of the Wi-Fi setting with the "Device" tag.
# We then cut out the first part of the entries and keep with is on the right side (of the ":".
# And finaly we strip out the extra space (to be neat).

WiFiDev="`networksetup -listallhardwareports | grep -A 1 "Wi-Fi" | grep -C 0 "Device" | cut -d ":" -f 2 | tr -d " "`"

# echo $WiFiDev

## Now turn it off.

networksetup -setairportpower $WiFiDev off

echo "Turning off the port at $WiFiDev"

exit 0
till next time

Set Proxy on all available network services

When you want to set the proxy on all available network services (say with JAMF’s Casper Suite at imaging time?)

#!/bin/bash

## A few variables we'll need for later

ProxyURL=http\:\/\/foo\/bar\.pac
declare -a NetServs

# Dealing with IFS as we need to alter it to avoid space issues.
OrigIFS=$IFS
IFS=$'\n'

#Define what Network Services are available.
NetServs=( `networksetup -listallnetworkservices | cut -d "." -f 2-` )

# Go through each network service and set the autoproxy.

for NetServ in ${NetServs[*]}; do
networksetup -setautoproxyurl "$NetServ" $ProxyURL
echo "$NetServ" is now set to use the proxy at $ProxyURL
done

exit 0

Enjoy.

till next time

Googled in any search engine

We all get cold sales calls. I just got one for a ‘major’ networking opportunity. I was willing to listen and go along with their sales pitch until this line…

"You will be able to be Googled in any major search engine."

If you are going to be calling up a techie, you should be a bit more aware of what you are saying. Yes, she most likely meant searched in any major search engine. But that’s not what she said. It was at that point that I knew I was not going to be giving that company any of my money.

It’s Friday, let us go rejoice.

Till next time.