Skip to content

Instantly share code, notes, and snippets.

@phoolish
Created May 22, 2013 14:32

Revisions

  1. phoolish created this gist May 22, 2013.
    37 changes: 37 additions & 0 deletions yum_updates.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash
    #
    # Checks yum for updates and passes the count to collectd.
    #
    # Requriments:
    # - collectd_exec_plugin
    # - yum-plugin-security package
    #
    # <Plugin exec>
    # Exec "nobody" "/path/to/yum_update.sh"
    # </Plugin>
    #
    # Or to define the interval.
    # <Plugin exec>
    # Exec "nobody" "/path/to/yum_update.sh" "-i" "60000"
    # </Plugin>
    #

    HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
    # run every 12 hours
    INTERVAL="43200"

    while getopts "i:" c; do
    case $c in
    i) INTERVAL=$OPTARG;;
    *) echo "Usage: $0 [-i <interval in seconds>]";;
    esac
    done

    while [ $? -eq 0 ]; do
    updates=$(yum check-update -q | sed "1 d" | wc -l)
    security_updates=$(yum check-update -q --security | sed "1 d" | wc -l)

    echo "PUTVAL $HOSTNAME/yum/updates interval=$INTERVAL N:$updates"
    echo "PUTVAL $HOSTNAME/yum/security_updates interval=$INTERVAL N:$security_updates"
    sleep "$INTERVAL"
    done