Auc, egrep, and generating an alert for updates

I'd like to use auc to alert me when/if there is a new release. I want to do something like:

auc -r -c | egrep '^Nothing' || msmtp

I'm having trouble understanding how the following results make sense:

root@OpenWrt:~# auc -c -r
auc/0.3.1-1
Server:    https://sysupgrade.openwrt.org
Running:   22.03.2 r19803-9a599fee93 on ramips/mt7621 (ubnt,edgerouter-x)
Available: 22.03.2 r19803-9a599fee93
Nothing to be updated. Use '-f' to force.

root@OpenWrt:~# echo $?
0

root@OpenWrt:~# auc -c -r | egrep '^Nothing'
Nothing to be updated. Use '-f' to force.

root@OpenWrt:~# echo $?
1

root@OpenWrt:~# echo "Nothing" | egrep '^Nothing'
Nothing

root@OpenWrt:~# echo $?
0

What part of the results are you having difficulty understanding?

The different exit codes from egrep with seemingly similar results.

To the OP, do you have to make it a one liner? Can’t explain the exit code difference, but my first thought would be to store the result in a variable and then test for zero or non-zero length (-z or -n) in an if statement.

Thanks @lantis1008 - well, I suppose I could do that (I'll try), but is this a bug? Should I tell the developers?

Also, auc itself returns with exit code 0, even though there is nothing to update. Is there some way to use the switches to get it to show whether there is an update or not via an exit code? If not, it seems to me there should be.

The auc bit is more of a feature request in my opinion. You could ask, but the fastest way to get what you want is to try coding it yourself and opening a PR on GitHub.

For the shell scripting, I don’t know it well enough to know if it’s a bug or quirky but expected behaviour. Maybe someone with more scripting knowledge will chime in.

Ok, I'll wait. Or maybe check on the development list if I don't hear back in a bit.

Yes, auc may be a feature request, but I was really asking if it's already doable with some combination of switches, and I just haven't figured it out yet. I'm fairly new to owrt (first install), and I'm feeling hobbled by the lack of man pages, either in the distro or online.

It might be a simple case of stdout vs stderr streams coming out of auc. You should research this more but your fix might be to redirect stderr "2" to stdout "&1" in the auc command:
auc -c -r 2>&1 | egrep '^Nothing'

My test results:
Original:

root@R4S-wrt:~# auc -c -r | egrep '^Nothing'
Nothing to be updated. Use '-f' to force.
root@R4S-wrt:~# echo $?
1
root@R4S-wrt:~#

New way:

root@R4S-wrt:~# auc -c -r 2>&1 | egrep '^Nothing'
Nothing to be updated. Use '-f' to force.
root@R4S-wrt:~# echo $?
0
root@R4S-wrt:~#

Testing with temp files shows my idea likely to be valid:

root@R4S-wrt:~# auc -c -r 2>/tmp/aucerr 1>/tmp/aucstd |egrep '^Nothing'
root@R4S-wrt:~# echo $?
1
root@R4S-wrt:~# cat /tmp/aucstd 
auc/0.3.1-1
Server:    https://sysupgrade.openwrt.org
Running:   22.03.2 r19803-9a599fee93 on rockchip/armv8 (friendlyarm,nanopi-r4s)
Available: 22.03.2 r19803-9a599fee93
root@R4S-wrt:~# cat /tmp/aucerr
Nothing to be updated. Use '-f' to force.
root@R4S-wrt:~#

This external page shows the exit codes from gnu grep: https://www.gnu.org/software/grep/manual/html_node/Exit-Status.html
Maybe it is the same for posix and busybox in OpenWrt.

You could also use the temp file to test against in your script.
I'm no expert so test various scenarios, review the auc code or seek advise from an expert.

2 Likes