Tuesday, 11 November 2014

HP OMU: update agent bash script

Massupdate agent oa:

http://sysadminz.ru/index.php?topic=329.0

#!/usr/bin/sh
#-- environment
FILE="/tmp/check_version.out"
FILE_GOOD="/tmp/check_version_good.out"
FILE_BAD="/tmp/check_version_bad.out"
TMP_FILE=${FILE}_${RANDOM}
MAIL_LIST="admin@domain.net"
OPC_DIR="/opt/OV/bin/OpC"
CURR_VER="08.60.501" # Версия, до которой обновляемся
C_BAD=0
C_GOOD=0
#-- main
>$FILE_GOOD
>$FILE_BAD
echo '<table border=1 width="100%">' > $FILE
for NODE in `/usr/bin/opcnode -list_nodes | awk '/Name/ {print ($3)}' | grep -v "^[0-9]\{1,3\}\." | grep -v "<\*>" | sort`
do
        SNODE=`echo $NODE | cut -f1 -d"."`
        echo "$SNODE \c" > $TMP_FILE
        $OPC_DIR/opcragt -agent_version $NODE|grep "HPOvEaAgt"|\
        sed 's/.*\([0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9]\)  pkg[ ]\(.*\)/\1 \2/ '     1>>$TMP_FILE 2>&1
        cat $TMP_FILE|grep -q "$CURR_VER"
        RESULT=$?
        if [ "$RESULT" = "1"  ]
        then
            cat $TMP_FILE | awk '{print "<tr><td>"$1"</td><td>"$3"</td><td>"$2"</td></tr>"}' >> $FILE_BAD
            C_BAD=`expr $C_BAD + 1`
        else
            cat $TMP_FILE | awk '{print "<tr bgcolor=green><td>"$1"</td><td>"$3"</td><td>"$2"</td></tr>"}' >> $FILE_GOOD
            C_GOOD=`expr $C_GOOD + 1`
        fi
done
echo '<tr bgcolor="#C0C0C0"><td>Summary</td><td>Wrong</td><td>Correct</td></tr>' >> $FILE
echo "<tr bgcolor=\"#C0C0C0\"><td>"`expr $C_BAD + $C_GOOD`"</td><td>$C_BAD</td><td>$C_GOOD</td></tr>" >> $FILE
echo '<tr bgcolor="#C0C0C0"><td> </td><td> </td><td> </td></tr>' >> $FILE
cat $FILE_BAD >> $FILE
cat $FILE_GOOD >> $FILE
echo "</table>" >> $FILE
echo "[include $FILE text/html base64]"|elm -s "Check_version report" $MAIL_LIST 1>/dev/null 2>&1
rm $TMP_FILE



No comments:

Post a Comment