Handy little “rug lu” commands

This question came in from Steve in a comment:  “…I am looking for a way to run the “rug lu” command and have it dump the output my local machine to look over and see what updates I have ahead of me…

So I replied, but then I thought of alot more stuff… so much more in fact, that I thought it deserved its own post…  So here you go, an “extended play” version of my reply…

For OpenSuse servers…

Please see this post:  http://yourlinuxguy.com/?p=324

That is exactly what I was going for in the post linked above.  If you download that script I mention there in that post, then change it to executable (for instance, chmod 700 filename), then run it, it will generate a comparison and dump the results to screen and output file, and tell you where the file is.

The script will not actually update your system (in the current state); it will only report about potential updates. But, if you get more brave, you can go in the file and un-comment the zypper lines I commented out that actually update the system…  Or change them to rug lines…  Which leads me to…

For SLES/OES servers…

Just do this:
rug lu > /tmp/lu.txt

…then go look at the file with:
less /tmp/lu.txt

…Or, you could have it emailed to yourself like this:
rug lu |mailx -s "Updates from $HOSTNAME" root

…of course, that assumes that you are having root mail sent off the box (see this if you’re not).  Otherwise you use your email address instead of root.

But what if you want to limit the updates list?  Perhaps something more specific; to report only that in which you are interested in updating?  See these examples (note that you can change the rug catalog to taste, of course, depending on your version):

rug lu -t patch SLES10-SP3-Updates OES2-SP2-Updates |mailx -s "Updates from $HOSTNAME" root

By adding a grep statement to block out the “optional” lines, the result is even cleaner.  Here’s an example:

rug lu -t patch SLES10-SP3-Updates OES2-SP2-Updates |grep -v optional|mailx -s "Updates from $HOSTNAME" root

On the other hand, by only *including* the lines you want (instead of excluding those you don’t), you lose the headers and separators, and only get the lines in which you’re interested (if any).  Here’s an example:

rug lu -t patch SLES10-SP3-Updates OES2-SP2-Updates |grep -e security -e recommended|mailx -s "Updates from $HOSTNAME" root

Or if you were to be running this in a mass-batch (hmm… future post…) to a bunch of servers or a cron job, and just don’t want an email at all if there are no results (and you *do* want an email if there *are* results):

RESULT=`rug lu -t patch SLES10-SP3-Updates OES2-SP2-Updates |grep -e security -e recommended`;if [ "XX$RESULT" != "XX" ];then echo "optional updates:" $RESULT |mailx -s "Updates from $HOSTNAME" root;fi

Okay now, that’s good; but here’s a prettier version of the same…  Okay, the command itself is uglier, but the resulting email is prettier at least.  The above one doesn’t format the results as nicely as I like (losing all the line returns), so I had to make use of a temp file to maintain the output formatted with returns:

rug lu -t patch SLES10-SP3-Updates OES2-SP2-Updates |grep -e security -e recommended>/tmp/ruglu.txt;RESULT=`cat /tmp/ruglu.txt`;if [ "XX$RESULT" != "XX" ];then cat /tmp/ruglu.txt|mailx -s "Updates from $HOSTNAME" root;fi

And that’s about it, with a couple closing thoughts:  Remember, it’s definitely a good idea to do a “rug ping” before doing this, to wake it all up, so you’re not waiting in silence for each command to run while it wakes up.  Then if you actually need updates, do this:

rug up -y -t patch -g security -g recommended SLES10-SP3-Updates OES2-SP2-Updates

Do you feel updated?  I do.


Leave a Comment

Your email address will not be published. Required fields are marked *