bashgrepyum

How can I grep a count of available updates from yum check-updates


I want to check if updates are available, and if so, perform some steps before I install the updates. I run yum check-updates to see a list of updates available for installed packages, but I'd like to grep this and get a count that I can use for some logic in a bash script. So ideally, I would like to grep that output of check-updates and return 0 if there are no updates, or if five updates are available then I would like the grep to return 5.

How can I grep this to return the count?


Solution

  • This combination of awk and grep gives the count of available updates for installed packages:

    yum check-updates | awk 'p;/^$/{p=1}' | grep -c "\."
    

    This was based on the info in How to get just a list of yum updates