EA Script For Retirement Date

New Contributor II

I am not a shell scriptor yet (just purchasing Learning the Bash), but in the meantime, does anyone have a EA with a script that adds a specified time (three years for us) to the PO date to establish a retirement date for all computers?


Valued Contributor

Two approaches:

  1. Perhaps it's not worth the effort to craft an EA; your basic Inventory Report will show you the model code, like 15-inch Retina MacBook Pro (Mid 2012). It's trivial for us humans to look at this and add 3, or rather to be looking at this list in 2014 and know that models popping up with a 2011 code are due for replacement. You could even make a report that looks for models "like 2011". So that's one answer.

  2. Edit: The answer below is better, but I'll leave this one here: As to your specific query, you'll need GSX and an API account on the JSS. You'll use the API to pull information about the system's purchase data and add 3. I can't give you the exact script you're looking for (don't have GSX; long story), but it will have similar components to this one, which can help you find the management account for a Mac:


MacAdd=$( networksetup -getmacaddress en0 | awk '{ print $3 }' | sed 's/:/./g' )

ManAccount=$( curl -s -u $apiUser:$apiPass "$apiURL$MacAdd" | xpath /computer/general/remote_management/management_username[1] | sed 's/<management_username>//;s/</management_username>//' )
if [[ "$ManAccount" != "" ]]; then
    echo "<result>$ManAccount</result>"
    exit 0

Legendary Contributor III

If you already have the P.O. Date as information for each Mac, while this isn't exactly what you asked for, you'd could create a Smart Group with the following criteria

P.O. Date  |  More than X days ago  |  1095

1095 is 3 years in days, so it would gather all Macs with P.O. Dates that are beyond the 3 year timeframe.
You could of course lower that number by x days, like 30, 60, whatever to be alerted to Macs that are only a few months short of the 3 year mark from Purchase.
Set up an email on Smart Group change to occur and you should get an email about any Macs that fail into that group.

Valued Contributor

Throwing yet another possibility in here:
Given that you have the PO Date populated in your JSS, you could pull that using the API,
add three years to it and write it back to the "Warranty Expires" field in the Purchasing Info tab.


MacAdd=$(networksetup -getmacaddress en0 | awk '{ print $3 }' | sed 's/:/./g')

podate=$(curl -s -u $apiUser:$apiPass $apiURL$MacAdd/subset/purchasing | xpath '//po_date' 2>&1 | awk -F'<po_date>|</po_date>' '{print $2}')

podateshort=$(echo $podate | tr -d "-")

retirement=$(date -v+${retirementAge}y -j -f "%Y%m%d" "$podateshort" +"%Y-%m-%d")

curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${apiUser}:${apiPass}" -d "<computer><purchasing><warranty_expires>$retirement</warranty_expires></purchasing></computer>" "${apiURL}${MacAdd}"

Note that my (date-)scripting-Fu is kinda weak, i'm sure someone can improve that...

New Contributor II

Thanks for your help everyone. Looks like any one of these can get us there.