Checking for updates on the command line

Status
Not open for further replies.

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Should be pretty straightforward - I just want to check to see if there are available updates, just like going to the System... Update tab and clicking "Check Now" - but I want to do that from the command line.

Did a bit of searching but most of what I found was problems updating. I want to check for updates, and yes, I know it emails me when there's an update available. I'm looking to add the update check to my monitoring system. I've got checks telling me if updates are available on the other systems I monitor, so it'd be nice to be able to do the same with the FreeNAS box.

Is it as simple as running:

/usr/local/bin/freenas-update check

and looking for "Status: No updates available"? Just want to make sure there aren't any key steps I'm missing, like checking http://update.ixsystems.com/FreeNAS/

Thank you!
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Seems to be:

Code:
[root@ASC-FN01] ~# /usr/local/bin/freenas-update check

Verify command = ['/usr/local/libexec/verify_signature', '-K', '/usr/local/share/certs/Production.pem', '-C', '/usr/local/share/certs/iX-CA.pem', '-S', u'qclWu8kvPGZ5lb2vTsls5ypq8onsEjYgN+BYczAaCKJoBP/RzLOQzlBCANJhOGTv+SnvIKr9D16N+NeOoEziAC7Evxuzvw9W8LQaI+54EpGbNfh+I0mIpEWZmH/4bvqHYskG00jB7PaaoiMCpgipn+Z34fALhbMqES5xE8N2Mo78iNq9GJilV/HejKODYw+8T9/TgAKn1KdJyo0K+RqX6L79NeV6gp3CWuVMB3VyFGezVL6hsKh7jJb8PnBWQhImrQDHOkBujCEgTB1lsZ+FmqL1hDuqafa+gFo8pfDqOzlivZgvExzdQmxPdAj7jUxEcoJ9PKBXMymsgWKfSVfbiw==', '-R', '/tmp/tmp80U5Vs.pem']
Signature check succeeded
Going to try checking cached manifest /var/db/system/update/MANIFEST
Got this exception: [Errno 2] No such file or directory: '/var/db/system/update/MANIFEST'
Status: No updates available
Total Progress: [########################################] 100.00%
 

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
That's what I was afraid of - that output is nasty. There are control characters before the "Status: No updates available" and there are two instances of that text that show up in the output. Can't just grep "^Status" - definitely not intended for use in a scripted environment.

I've got that in place right now - will see if it changes the next time an update is available and if my monitoring catches it.
 

Linkman

Patron
Joined
Feb 19, 2015
Messages
219
Possible to check a return code, and ignore the text output?
 

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Looked at that... returns a 1 when it reports no updates available. If it returns a 0 when updates are available, that'd be usable, but without any way to test that (that I can think of) I can't rely on it.

Oh, also, all that output is to STDERR, so you've got to redirect it to do anything useful with the output:

Code:
/usr/local/bin/freenas-update check 2>&1 | grep -q "Status: No updates available"


It looks like the control chars are trying to give some sort of progress meter, but it returns quickly enough that that isn't needed.

I looked at the code a little bit, but it was late, so I didn't really dissect it.
 
Last edited:

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Likely what I'll have to do, but was hoping there was something built in and I could just run that - so I didn't have to re-reverse engineer it when the next major update changes the update checking process.
 

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Aha! I figured it out. Didn't need to update the script, just had to use the -v option and direct all of STDERR to /dev/null:

Code:
11-NAS:~$ sudo ./freenas-update -v check 2> /dev/null
No updates available


I can catch that output and check it for "No updates available" and that looks like it'll work.

Here's a short script that is compatible with Nagios and its derivatives:

Code:
#!/bin/bash

# The command to check for updates
#  * make sure to have the "-v" option which causes output to STDOUT.
#    Otherwise all output goes to STDERR with control chars and such
upcheck="/usr/local/bin/freenas-update -v check"

# Run with sudo if we're not root
if (( EUID ))
then
          SUDO=sudo
fi

# Run the command, catching STDOUT and dumping STDERR (progress bars and other noise)
out="$($SUDO $upcheck 2> /dev/null)"

# Check the output
if [[  "$out" == 'No updates available' ]]
then
          echo "OK: No updates available."
          exit 0
else
          echo "WARNING: Updates may be available:"
          echo $out
          exit 1
fi
 
Last edited:

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Yay, it works! Got this alert this morning:

ln5FSJu.png


Had to LOL at my non-committal "Updates may be available" message. :)

Checked my FreeNAS box, and...

r5xSw1v.png


Looking at the output of the script, it returns _no_ STDOUT when there are updates, and it does in fact exit with a 0 status:

Code:
3-NAS:~$ sudo /usr/local/bin/freenas-update -v check 2> /dev/null
4-NAS:~$ echo $?
0


So:
  • No updates available will give STDOUT (with the -v option) and exit with a status of 1
  • Updates available will give no STDOUT and exit with a status of 0
  • You may need to adjust timeout values on your monitoring system, as this script takes about 8 seconds to run. If your FreeNAS host is remote or slow to respond, it may run over the 10 second default of most Nagios-based monitoring systems.
Hope this is helpful to someone!
 
Last edited:

cmh

Explorer
Joined
Jan 7, 2013
Messages
75
Here's the updated script which uses the exit status instead of the command output:

Code:
#!/bin/bash

# The command to check for updates
upcheck='/usr/local/bin/freenas-update check'

# Run with sudo if we're not root
if (( EUID ))
then
    SUDO='/usr/local/bin/sudo'
fi

# Run the command and:
#  - Dump all output
#  - check the exit status:
#     0 = updates available
#     1 = no updates
if $SUDO $upcheck > /dev/null 2>&1
then
    echo 'WARNING: Updates are available.'
    exit 1
else
    echo 'OK: No updates available.'
    exit 0
fi
 
Joined
Apr 23, 2017
Messages
30
Any way to check the motherboard update level from the console? Using a Supermicro X10SL7-F.
 
Status
Not open for further replies.
Top