Mac OS X Terminal – Get Computer Information

| | | |
clear

echo "Inventory Script - Running...."

# Variables - Start
# Get IP - Start
netadapter=en0
ip=$(ipconfig getifaddr $(echo $netadapter))
#echo $ip
#echo $netadapter

counter=1
while [ $counter -le 10 ]
do
if [ -z "$ip" ]
then
#echo $counter

netadapter=$(echo "en"$counter)
ip=$(ipconfig getifaddr "en"$counter)

fi
((counter++))
done
#echo $ip
#echo $netadapter

# Get IP - Stop

declare dDateTime=$(date +%Y_%m_%d)

# Variables - Stop

OSvers1=$( sw_vers -productVersion | cut -d. -f1 )
OSvers2=$( sw_vers -productVersion | cut -d. -f2 )
OSvers3=$( sw_vers -productVersion | cut -d. -f3 )

case $OSvers2 in
    8)
OSName="Mountain Lion"
;;
9)
OSName="Mavericks"
;;
10)
OSName="Yosemite"
;;
11)
OSName="El Capitan"
;;
12)
OSName="Sierra"
;;
default)
OSName="Unknown"
;;
esac

echo "      Computer OS: Mac OS X - $OSName $OSvers1.$OSvers2.$OSvers3" > ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
echo "      Computer Name: $(scutil --get ComputerName)" >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
echo "      User Name: $(whoami)" >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
echo "      IP Address: $ip" >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
echo "      Network Adapter: $netadapter" >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
echo "      File Vault: $(fdesetup status)" >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt
/usr/sbin/system_profiler SPHardwareDataType | grep "Model Name" -A12 >> ~/Desktop/$(whoami)_$(scutil --get ComputerName)_InventoryReport_$dDateTime.txt

echo "Inventory Script - Completed"
Originally Posted on September 1, 2016
Last Updated on December 13, 2016
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.