bashyum

How to get just a list of yum updates


OK I have always had this problem. I want JUST the available updates listed in a file via bash script from a Linux system (RHEL or Fedora) using yum but I always have to deal with the Header information created which looks like this:

    Loaded plugins: XXXX-repo  XXXX-updates
                  : WWWWWW-repo  something-updates  QQQQQ-updates
     Updated packages
     package1.i686         1:234                  RHEL 6.5 updates
     package2.i686         1:234                  RHEL 6.5 updates
     package3.i686         1-234                  RHEL 6.5 updates
     package4.noarch       1.234                  RHEL 6.5 updates

All I want is a list of package1,package2, etc. which seems simple enough but it isn't because I can't just grep on "updates" or ":". Am I looking at this wrongly? Why would I not want to capture what updates were found in a script? Should I just update and check what has been updated instead? Thoughts?

PS> I can not use --noplugins option.

EDIT: So far I have come up with this,

     sudo yum check-update | grep "\." | awk '(NR >=1) {print $1;}' | grep '^[[:alpha:]]'

Basically grab the lines with a period in them, the first line, and make sure it first contains alpha letters. Perhaps over done but it seems to work.


Solution

  • To only print lines following (but not including) "Updated packages"

    yum check-update | awk 'p; /Updated packages/ {p=1}'
    

    Note, on my Fedora system, a blank line separates the "header" from the list of updatable packages, so I would use awk 'p;/^$/{p=1}'