Search code examples
shellfor-loopsolariscounterwc

Dynamic Patch Counter for Shell Script


I am developing a script on a Solaris 10 SPARC machine to calculate how many patches got installed successfully during a patch delivery. I would like to display to the user:

(X) of 33 patches were successfully installed

I would like my script to output dynamically replacing the "X" so the user knows there is activity occurring; sort of like a counter. I am able to show counts, but only on a new line. How can I make the brackets update dynamically as the script performs its checks? Don't worry about the "pass/fail" ... I am mainly concerned with making my output update in the bracket.

for x in `cat ${PATCHLIST}`
do
    if ( showrev -p $x | grep $x > /dev/null 2>&1 ); then
        touch /tmp/patchcheck/* | echo "pass" >> /tmp/patchcheck/$x
        wc /tmp/patchcheck/* | tail -1 | awk '{print $1}'
    else
        touch /tmp/patchcheck/* | echo "fail" >> /tmp/patchcheck/$x
        wc /tmp/patchcheck/* | tail -1 | awk '{print $1}'
    fi
done

Solution

  • Here is how I got my patch installation script working the way I wanted:

    while read pkgline
    do
        patchadd -d ${pkgline} >> /var/log/patch_install.log 2>&1
        # Create audit file for progress indicator
        for x in ${pkgline}
        do
            if ( showrev -p ${x} | grep -i ${x} > /dev/null 2>&1 ); then
                echo "${x}" >> /tmp/pass
            else
                echo "${x}" >> /tmp/fail
            fi
        done
        # Progress indicator
        for y in `wc -l /tmp/pass | awk '{print $1}'`
        do
            printf "\r${y} out of `wc -l /patchdir/master | awk '{print $1}'` packages installed for `hostname`.  Last patch installed: (${pkgline})"
        done
    done < /patchdir/master