9

Am building a script to find out when a list of servers was last fully updated with yum update.

I can find it by a history |grep "yum update"|head -n 1 however, the problem is that a user could have launced it but didn't type "y" in the prompt.

Another way I tried was with yum history

ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
   109 | <xyz user>              | 2015-08-20 07:18 | Erase          |   1 E<
   108 | root <root>              | 2015-08-18 08:56 | Update         |    3 >
   107 | root <root>              | 2015-08-14 07:39 | Update         |    1
   106 | root <root>              | 2015-08-14 07:38 | Update         |    1
   105 | root <root>              | 2015-08-14 07:38 | Update         |    3
   104 | root <root>              | 2015-08-13 07:31 | Update         |    1
   103 | root <root>              | 2015-08-11 05:46 | Update         |    1
   102 | root <root>              | 2015-08-11 05:46 | Update         |    2
   101 | root <root>              | 2015-08-11 05:45 | Update         |    3
   100 | root <root>              | 2015-08-11 05:45 | Update         |    3
    99 | root <root>              | 2015-08-10 20:41 | Update         |    1
    98 | root <root>              | 2015-08-05 02:35 | Update         |    1
    97 | root <root>              | 2015-05-14 10:52 | Update         |    1
    96 | root <root>              | 2015-05-01 02:59 | Obsoleting     |    2
    95 | root <root>              | 2015-04-09 16:06 | Update         |    1  <
    94 | <xyz.user>            | 2015-03-28 08:49 | Update         |    1 ><
    93 | <xyz.usert>            | 2015-03-28 08:14 | Erase          |    3 ><
    92 | <xyz.user>            | 2015-03-13 07:46 | Install        |    6 ><
    91 | <xyz.user>             | 2015-03-13 05:45 | I, U           |   24 >
    90 | root <root>              | 2015-03-04 01:24 | Update         |    3

But I can't find a way of determining the date the yum update was launched and was successful. Since if I check, for example, the transaction ID 108 which is marked as "Update" launched on 18th, I don't find the command yum update for that particular date :

history |grep 2015 |grep "yum update"

 5182  20150313-054444 > yum update

Another path I tried was with /var/log/yum.log but yum.log will show installs and updates also. If a package is updated while installing a package e:g: yum install varnish and it requires an update of certain packages eg:(varnish-libs-2.1.5-5.el6.i686, 3.0.7-1.el6.i686 etc) this will be shown as updated in the yum.log

Is there a way to find the date a yum update was launched and it was successful?

11

You almost answered your question. Here is a way you can find latest 5 updated packages:

grep Updated: /var/log/yum.log | tail -5

Output example:

Aug 05 13:28:34 Updated: virt-manager-common-1.1.0-9.git310f6527.fc21.noarch
Aug 05 13:28:34 Updated: glusterfs-libs-3.5.5-2.fc21.i686
Aug 05 13:28:35 Updated: virt-manager-1.1.0-9.git310f6527.fc21.noarch
Aug 05 13:28:36 Updated: virt-install-1.1.0-9.git310f6527.fc21.noarch
Aug 05 13:28:38 Updated: glusterfs-3.5.5-2.fc21.i686
  • 1
    cat is misused (take a look at The Useless Use of Cat Award ) , and -10 is not needed as tail shows ten lines per default: so it's better: grep Updated: /var/log/yum.log | tail – sebelk Aug 21 '15 at 12:23
  • 1
    You are absolutely wright! But that's an old habit to cat everything ) 10 (changed to 5) is needed because you can choose any number of records to grep. That's why i leaved number with grep. – obohovyk Aug 21 '15 at 12:27
  • This shows only last 5 updated packages. Consider Senario below: If a package is updated while installing a package e:g: yum install varnish and it requires an update of certain packages eg:(varnish-libs-2.1.5-5.el6.i686,3.0.7-1.el6.i686 etc) this will be shown as updated in the yum.log. Whereas I want exactly when the yum update was launched and was run succesfully, not the last 5 updated packages. – Kheshav Sewnundun Aug 21 '15 at 13:21
  • You may want to use auditd and creating rules for yum execution. – sebelk Aug 22 '15 at 1:43
  • It's possible that yum.log has been cleared out if yum hasn't been used since logs rotated. If that's the case you can grep through e.g. /var/log/yum.log-20180101 etc – user8675309 Mar 19 at 16:08
5

First you need to define what "upgrade" means. Eg. upgrade with only a newer kernel will be an install (and likely an erase of an older one). If someone does "upgrade foo" does that count? What about "distro-sync" that ends up just doing upgrades (or if it doesn't)? Does it count if the transaction failed?

Then stop greping output, it will only lead to pain and suffering.

Using the API is pretty simple, eg (latest time a transaction was started to upgrade any package):

import yum
import time

yb = yum.YumBase()
for old in yb.history.old():
    if "Update" in (hpkg.state for hpkg in old.trans_data):
        print "Latest Update:", time.ctime(old.beg_timestamp)
        break

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.