#!/bin/bash

#MAR052013

bin_check () {


myres=""

if [ -f /usr/local/cliff/$1_stat_change -a /usr/local/cliff/$1_stat_modify ]; then

        eval cur_$1_modify_time=`stat $2 | grep Modify | awk {'print $3'}`
        eval old_$1_modify_time=`cat /usr/local/cliff/$1_stat_modify`

        eval curr_$1_change_time=`stat $2 | grep Change | awk {'print $3'}`
        eval old_$1_change_time=`cat /usr/local/cliff/$1_stat_change`

        eval currmod=$(echo \$cur_$1_modify_time)
        eval oldmod=$(echo \$old_$1_modify_time)

        eval currchange=$(echo \$curr_$1_change_time)
        eval oldchange=$(echo \$old_$1_change_time)


        if [ "$currmod" == "$oldmod" -a "$currchange" == "$oldchange" ]; then
                myres=`echo "OK: $2 stat result fine"`
        elif [ "$currmod" != "$oldmod" -a "$currchange" != "$oldchange" ]; then
                myres=`echo "CRITICAL: Stat check failed. Both Modify and Change time altered for $2"`
        elif [ "$currmod" != "$oldmod" ]; then
                myres=`echo "CRITICAL: Stat check failed. Modify time altered for $2"`
        elif [ "$currchange" != "$oldchange" ]; then
                myres=`echo "CRITICAL: Stat check failed. Change time altered for $2"`
        fi
else
        myres="Either /usr/local/cliff/$1_stat_change or /usr/local/cliff/$1_stat_modify missing"
fi

#echo "myres  - $myres"
}

finalres=""

bin_check sshd /usr/sbin/sshd
finalres=" $finalres  ----  $myres"



bin_check perl /usr/bin/perl
finalres=" $finalres  ----  $myres"

bin_check mysql /usr/bin/mysql
finalres=" $finalres  ----  $myres"

bin_check puppet /usr/bin/puppet
finalres=" $finalres  ----  $myres"


bin_check php /usr/bin/php
finalres=" $finalres  ----  $myres"





if [ "$(echo $finalres | grep CRITICAL)" ]; then
        echo $finalres | awk ' BEGIN {
        f = 1
} {
        for ( i = 1; i <= NF; i++)
        {
                if ( $i ~ /CRITICAL:/ )
                {
                        f = 1
                }
                if ( $i ~ /OK:/ )
                {
                        f = 0
                }
                if ( f == 1 )
                {
                        printf "%s ", $i
                }
        }
        printf "\n"
} '
        exit 2
else
        echo $finalres
        exit 0
fi

