Looking for docs on exit codes for freebsd-update updatesready and pkg upgrade --dryrun

I have a script that runs weekly to do routine maintenance: zpool scrubs, check disk smart attributes and run disk self-tests, ... I used to use nagios but it tended to supply a lot of info, most reporting "no action needed". My own version logs all responses only notifies me when action is needed (in some cases, using reworked nagios plugins). Optimally, I want to separate 3 scenarios: no updates, some updates and something went wrong.

I'm using RELEASE binary freebsd versions, no ports and few packages. I want to add code to tell me updates are needed. I found many posts on this forum recommending how to do updates and decided to look at the exit codes (hopefully) or text output of freebsd-update updatesready and pkg upgrade --dryrun. But I can't find documentation on the exit codes. The man page for freebsd-update updatesready says "Returns exit code 2 if there are no updates to install", and nothing else. man pkg and man pkg-upgrade say nothing about exit codes. My system doesn't need updates now and both commands return zero.

Any suggestions on where exit codes are documented? If not, I'm stuck grepping the response text and hoping it doesn't change :-(
 
Here's one I use with Zabbix: pkg version -qvRL= | wc -l | sed "s/^[ \t]*//" The output is 0 if there's nothing to upgrade, or it'll output the number of packages that are not up to date (version difference or orphaned).

The downside of this method is that zabbix (and nagios too) run on a user account, which isn't allowed to update the cached package catalog, so you're going to need to schedule a regular pkg update that updates the catalog.
 
Thanks! The downside you mention won't be a problem for me: I run parts of this script as root (e.g. hardware and checks). And I have higher confidence in my guesses for freebsd-update exit codes since they're at least partially documented, so pkg is the bigger issue. I'll try this out ASAP.
 
The downside you mention won't be a problem for me
In my case I have puppet running on those servers, a standard puppet run automatically updates that catalog. But you could simply schedule a pkg update with a root cronjob to run once an hour. That's usually enough for me, I don't need to check this every minute, once an hour or even once a day is usually enough.
 
Back
Top