Scripting softwareupdate

lilylily
New Contributor II

I'm trying to create a workflow for our school in which a computer can be booted, will check for available software updates and apply any necessary, and then check in with our JSS once no more software updates are identified. I'm curious if anyone has a solution for capturing the server response from the softwareupdate command? So far when I run:

#!/bin/bash
su=$(softwareupdate -l)
echo "$su"

The terminal output is:

No new software available.

Server response and then:

Software Update Tool

Finding available software

Output of echo "$su"

With the server response "No new software available." printing first and without regard for the output of the echoed variable. In other words I only ever seem to be able to programmatically capture "Software Update Tool" and "Finding available software". Does anyone have a solution for capturing the server response from the softwareupdate command?

1 ACCEPTED SOLUTION

cbrewer
Valued Contributor II

Try redirecting stderr to stdout:
currentupdates=$(softwareupdate -l 2>&1)

Also, I'd recommend either using this script directly or taking ideas from it.

Edit - the $su thing won't be a problem.

View solution in original post

2 REPLIES 2

cbrewer
Valued Contributor II

Try redirecting stderr to stdout:
currentupdates=$(softwareupdate -l 2>&1)

Also, I'd recommend either using this script directly or taking ideas from it.

Edit - the $su thing won't be a problem.

lilylily
New Contributor II

Thanks @cbrewer! That JSS script should do the trick.