Apple softwareupdate and installation success/failure feedback

May
Contributor III

Hi all

I'm looking for a way to confirm if the softwareupdate -da command has successfully downloaded all available updates or not, i'm also looking for feedback as to whether the JSS's built in software updates policy has successfully installed the updates or not.

At the moment i have a policy for each of these, as part of the download policy it adds a dummy receipt and for the install software policy it then deletes this dummy recepit, this is great if they complete successfully but if they fail the dummy receipt still gets added or deleted regardless.

The smart groups that the policies are scoped to is based on the existance of the dummy package, is it there ? or is it not ?.

I thought i could somehow use the exit code from the softwareupdate -da command but it appears that the exit code is 0 whether it completes or fails (i'm running the command then using echo $? to see the code) My understanding of exit codes is pretty limited so i may be barking up the wrong lamp post?!

Another way i've considered is to look at /Library/Updates before and after the command and see if it's modified or the size changes but have no idea how to start scripting that one yet.

Can anyone suggest a way of getting success or failure feedback from these two commands/policies ?

Thank you
Andy

8 REPLIES 8

May
Contributor III

Maybe ?
does it seem feasable that i could somehow look for "downloaded" in the output of the command and if it's there then use a mv command to shift a dummy package into the JAMF receipts folder

Result of command:
Software Update Tool
Copyright 2002-2012 Apple Inc.

Finding available software

Downloading iBooks Update
Downloading OS X Update
Downloading Digital Camera RAW Compatibility Update
Downloaded Digital Camera RAW Compatibility Update
Downloading Remote Desktop Client Update
Downloaded iBooks Update
Downloading iTunes
Downloaded Remote Desktop Client Update
Downloaded OS X Update
Downloaded iTunes
Done.

hkabik
Valued Contributor

create a log file from the output?

softwareupdate -da > /path/to/folder/diditdownload.log

bentoms
Release Candidate Programs Tester

@May Updates will download to /Library/Updates/

Also, the JSS can report on updates SWU's Pending as part of inventory collection.

May
Contributor III

Thanks @hkabik @bentoms

I've scavenged a script together that looks at the result of softwareupdate -da and creates a receipt if it downloads the updates successfully, tested with and without access to our SUS and it does what i need
and the JSS recognizes the receipt for my smart group criteria.

i may change it to look for "done" as well as "downloaded" (once i figure how)

Cheers again

#!/bin/sh
var=`softwareupdate -da`

softwareupdate -da

if [[ $var == *"Downloaded"* ]]
then
  mkdir /Library/Application Support/JAMF/Receipts/downloaded_updates_receipt.pkg

  exit 0
else

  echo "downloads failed"
  exit 1
fi

Chris_Hafner
Valued Contributor II

I have to agree with benToms here. I have a series of SMART groups that simply reflect the number of remaining software updates and fire off any policy I need based on that. Regardless, looks like you've got it sorted.

May
Contributor III

@Chris_Hafner Thanks Chris,

I have 2 policies running, one to download the updates then one to install them, on the download policy i need confirmation that the updates have successfully been downloaded so
i can then scope the install policy based on that.

Both of the policies are using "number of avaailable updates" as part of the criteria but on it's own it's not enough

Chris_Hafner
Valued Contributor II

@May Yep. I quite like your solution.

May
Contributor III

Just in case it's of use :)?

I've got a script working to check if the software update policy completes successfully and then delete a dummy receipt.

It will work when used in the JSS's inbuilt software update policy if the script is set to run after, or can just throw in softwareupdate -i -a into the script and use it on its own.

(Updated the script as previous did not work under certain conditions)

#!/bin/sh

var=$(softwareupdate -i -a 2>&1)

if [[ $var == *"Done."* ]] || [[ $var == *"No new software available"* ]] || [[ $var == *"No updates are available"* ]]
then
echo "updates complete"
  rm -rf /Library/Application Support/JAMF/Receipts/downloaded_updates_receipt.pkg
    exit 0

else
echo "updates failed" 
    exit 1
fi