Help with an if then statement. Apple Remote Desktop and setting Computer Info Field
This is a great script for network admins. It's able to set the AppleCare expiration date of the computer the script is run on in a computer info field allowing for easy sorting in Apple Remote Desktop. My issue is when a computer has an expired warranty I would like the script to set the info field to "Out of Coverage". The script runs as is and I've commented out the code that I think will be needed to do this. Any help would be appreciated. Thanks everyone.
#!/bin/bash
# warranty.sh
# Description: looks up Apple warranty info for
# this computer, or one specified by serial number
# Based on a script by Scott Russell, IT Support Engineer,
# University of Notre Dame
# http://www.nd.edu/~srussel2/macintosh/bash/warranty.txt
# Edited to add the ASD Versions by Joseph Chilcote
# Last Modified: 09/16/2010
# Edited 02/10/2011
# Updated support url
# Added function to write data to plist
## Add function to cycle through a csv file
###############
## GLOBALS ##
###############
# make sure you use a full path
PlistLocal=".appwarranty.plist"
WarrantyTempFile="/tmp/warranty.txt"
AsdCheck="/tmp/asdcheck.txt"
if [[ $# == 0 ]] ; then
SerialNumber=`system_profiler SPHardwareDataType | grep "Serial Number" | grep -v "tray" | awk -F ': ' {'print $2'} 2>/dev/null`
else
SerialNu开发者_开发技巧mber="${1}"
fi
[[ -n "${SerialNumber}" ]] && WarrantyInfo=`curl -k -s "https://selfsolve.apple.com/warrantyChecker.do?sn=${SerialNumber}&country=USA" | awk '{gsub(/\",\"/,"\n");print}' | awk '{gsub(/\":\"/,":");print}' | sed s/\"\}\)// > ${WarrantyTempFile}`
curl -k -s https://github.com/chilcote/warranty/raw/master/asdcheck -o ${AsdCheck} > /dev/null 2>&1
#################
## FUNCTIONS ##
#################
AddPlistString()
{
# $1 is key name $2 is key value $3 plist location
# example: AddPlistString warranty_script version1 /Library/ETC/appwarranty.plist
/usr/libexec/PlistBuddy -c "add :"${1}" string \"${2}\"" "${3}"
}
SetPlistString()
{
# $1 is key name $2 is key value $3 plist location
# example: SetPlistString warranty_script version2 /Library/ETC/appwarranty.plist
/usr/libexec/PlistBuddy -c "set :"${1}" \"${2}\"" "${3}"
}
GetWarrantyValue()
{
grep ^"${1}" ${WarrantyTempFile} | awk -F ':' {'print $2'}
}
GetWarrantyStatus()
{
grep ^"${1}" ${WarrantyTempFile} | awk -F ':' {'print $2'}
}
GetModelValue()
{
grep "${1}" ${WarrantyTempFile} | awk -F ':' {'print $2'}
}
GetAsdVers()
{
#echo "${AsdCheck}" | grep -w "${1}:" | awk {'print $1'}
grep "${1}:" ${AsdCheck} | awk -F':' {'print $2'}
}
###################
## CREATE PLIST ##
###################
if [[ ! -e "${PlistLocal}" ]]; then
AddPlistString warrantyscript version1 "${PlistLocal}"
for i in purchasedate warrantyexpires warrantystatus modeltype asd
do
AddPlistString $i unknown "${PlistLocal}"
done
fi
###################
## APPLICATION ##
###################
echo "$(date) ... Checking warranty status"
InvalidSerial=`grep "wc.check.err.usr.pd04.invalidserialnumber" "${WarrantyTempFile}"`
###
# this is the part I'm struggling with
#
###
#
# WarrantyStatus=`GetWarrantyStatus HW_SUPPORT_COV_SHORT`
# echo "WarrantyStatus == ${WarrantyStatus}"
# SetPlistString warrantystatus "${WarrantyStatus}" "${PlistLocal}"
#
###
# if above is equal to "Out of Coverage" then
# /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set4 -4 "Out of Coverage"
# and stop
# Else do below
###
if [[ -e "${WarrantyTempFile}" && -z "${InvalidSerial}" ]] ; then
WarrantyExpires=`GetWarrantyValue HW_END_DATE`
echo "WarrantyExpires == ${WarrantyExpires}"
SetPlistString warrantyexpires "${WarrantyExpires}" "${PlistLocal}"
else
if [[ -z "${SerialNumber}" ]]; then
echo " No serial number was found."
SetPlistString warrantystatus "Serial Not Found: ${SerialNumber}" "${PlistLocal}"
fi
if [[ -n "${InvalidSerial}" ]]; then
echo " Warranty information was not found for ${SerialNumber}."
SetPlistString warrantystatus "Serial Invalid: ${SerialNumber}" "${PlistLocal}"
fi
fi
####################################
## MONTH CONVERSION & ARD ENTRY ##
####################################
expdate=`date -j -f "%B %d, %Y" "${WarrantyExpires}" "+%Y-%m-%d"`
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set4 -4 "$expdate"
exit 0
Seems pretty straightforward. I assume the WarrantyStatus
variable is the thing that's supposed to hold this string:
if [[ "$WarrantyStatus" = "Out of Coverage" ]]; then
.../kickstart -configure -computerinfo -set4 -4 "$WarrantyStatus"
exit
fi
精彩评论