Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm managing a lot of Macs and each machines has several partitions with different OS versions.

I would like to create a script that I could run to do an inventory of all partitions of all machines and take note what OS is installed on each partition.

On the active partition, it would be easy to get it via the 'sw_vers' command. But what about on a different partition? I tried Google and I can't seem to find a close answer.

share|improve this question
    
Are you using Apple Remote Desktop to collect this information? It will assist you in running your scripts against hundreds of macs at once as well as ease the next tasks you will need once you have your inventory done. –  bmike Feb 10 '12 at 18:00
    
@bmike: I don't want to use Apple Remote Desktop in this case. Shell/Perl scripting is my preferred method. But yeah, your info would surely help in some other tasks later. Thanks for sharing :) –  icasimpan Feb 13 '12 at 1:25
    
Fair enough - it's all possible with ssh - especially easy if you exchange ssh keys so things are more scriptable. Do post back your solution - it's always welcome to answer your own question or edit answers to be even better. –  bmike Feb 13 '12 at 2:40

2 Answers 2

up vote 3 down vote accepted

The following command will give you the OS X version installed on volumeName:

defaults read /Volumes/volumeName/System/Library/CoreServices/SystemVersion ProductVersion

To get a list of each volume's OS version, you need a simple script that will get a list of volumes, search each one for the SystemVersion.plist, and report any that are found.

I found a script on on Mac OS X Hints, by Hal Itosis, that does just that (reposted below for convenience).

#!/bin/bash -
PATH=/bin:/usr/bin
export PATH
IFS=$'\n'

vList=$(df -l | sed '1d;s:^.*%[[:space:]]*::')
sPath=$(find -x /Volumes -maxdepth 1 -type l -not -inum 2)
pFile=/System/Library/CoreServices/SystemVersion

SysVers ()
{
   if [ -e "${1}${pFile}.plist" ]; then
      n="$1"; if [ "$1" = '/' ]; then n="$sPath"; fi
      x=`defaults read ${1}${pFile} ProductVersion`
      b=`defaults read ${1}${pFile} ProductBuildVersion`
      printf '%-16s %-8s %-8s\n' "${n##/*/}" "$x" "($b)"
   fi
}

if [ $# -eq 0 ]; then for v in $vList; do SysVers "$v"; done
else while [ $# -gt 0 ]; do SysVers "$1"; shift; done; fi
exit
share|improve this answer
    
Thank you so much for this. This is what I just need ;) –  icasimpan Feb 13 '12 at 1:20

You can use the diskutil command in terminal, which roughly speaking provides the ability to script up and perform the same actions as you can in the GUI version.

Using this it is possible to create a script that trawls for the info you need, but you have to be careful in specifying which disks you look at - if you do a blanket check on all disks, you will get disk images and all sorts included if you are not careful, plus you will end up with the recovery partitions and so on etc.

Also, the disk utility only provides the partition format, although that gives you a hint on what you can subsequently search on, i.e. look for a file called "mach_kernel" and chances are it's got OS X on it, it's it's got a "/windows" directory...etc etc, even then you will find partitions that are formatted on Mac or Win formats with no OS installed, so all in all not a trivial task. If you know where the OSX/Windows installer logs are you may be able to insert such logic as to pull out a service pack level, or a patch level etc, but I can't find out how to do that just yet.

Dans-iMac:~ stuffe$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *640.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            639.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *18.7 MB    disk1
   1:        Apple_partition_map                         32.3 KB    disk1s1
   2:                  Apple_HFS SMARTReporter           18.7 MB    disk1s2
Dans-iMac:~ stuffe$ diskutil info disk0s2
   Device Identifier:        disk0s2
   Device Node:              /dev/disk0s2
   Part of Whole:            disk0
   Device / Media Name:      Customer

   Volume Name:              Macintosh HD
   Escaped with Unicode:     Macintosh%FF%FE%20%00HD

   Mounted:                  Yes
   Mount Point:              /
   Escaped with Unicode:     /

   File System Personality:  Journaled HFS+
   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)
   Journal:                  Journal size 49152 KB at offset 0x129d000
   Owners:                   Enabled

   Partition Type:           Apple_HFS
   OS Can Be Installed:      Yes
   Media Type:               Generic
   Protocol:                 SATA
   SMART Status:             Verified
   Volume UUID:              7B3DEC51-1C86-37B5-95CE-888AE0EBD610

   Total Size:               639.3 GB (639275270144 Bytes) (exactly 1248584512 512-Byte-Blocks)
   Volume Free Space:        343.5 GB (343520002048 Bytes) (exactly 670937504 512-Byte-Blocks)
   Device Block Size:        512 Bytes

   Read-Only Media:          No
   Read-Only Volume:         No
   Ejectable:                No

   Whole:                    No
   Internal:                 Yes
   Solid State:              No

Dans-iMac:~ stuffe$ mountpoint=`diskutil info disk0s2 | grep "Mount Point" | awk '{print $3}'`
Dans-iMac:~ stuffe$ ls -l $mountpoint | grep -E "mach_kernel|windows"
-rw-r--r--@  1 root  wheel  15565404 10 Aug  2011 mach_kernel
Dans-iMac:~ stuffe$ 

Putting all this together in a suitable loop that identifies all the disks you are interested in, removing disk images USB sticks etc, and setting to either run remotely via SSH or whatever....is left as an exercise for the interested...

share|improve this answer
    
this is also a good info. Thanks for sharing :) –  icasimpan Feb 13 '12 at 1:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.