Fix bugs: Exec some script return error when use grep -c, and clamav daily file extension maybe changed.

This commit is contained in:
samson 2018-12-06 16:01:22 +08:00
parent 00ab71cc2e
commit 8798f43866
3 changed files with 8 additions and 6 deletions

View File

@ -32,10 +32,11 @@ audit () {
crit "$FILE does not exist"
FNRET=2
else
COUNT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILE | grep -c "${OPTIONS}")
ok "$FILE does exist"
COUNT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILE | grep "${OPTIONS}" | wc -l)
if [ $COUNT -gt 0 ]; then
ok "$OPTIONS is set in $FILE."
VALUE=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILE | grep -c ".*[[:space:]].*${OPTIONS}[[:space:]].*${OPVALUE}")
VALUE=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILE | grep ".*[[:space:]].*${OPTIONS}[[:space:]].*${OPVALUE}" | wc -l)
if [ $VALUE -eq 0 ]; then
crit "$OPTIONS value is incorrect in $FILE"
FNRET=4

View File

@ -19,16 +19,17 @@ UPDATE_SERVER='clamav-freshclam'
# This function will be called if the script status is on enabled / audit mode
audit () {
if [ $(systemctl | grep $VIRULSERVER | grep -c "active running") -ne 1 ]; then
if [ $(systemctl | grep $VIRULSERVER | grep "active running" | wc -l) -ne 1 ]; then
crit "$VIRULSERVER is not runing"
FNRET=1
else
ok "$VIRULSERVER is runing"
UPDATE_DIR=$(grep -i databasedirectory "$CLAMAVCONF_DIR" | awk '{print $2}')
if [ -d $UPDATE_DIR -a -e $CLAMAVCONF_DIR ]; then
NOWTIME=$(date +"%s")
VIRUSTIME=$(stat -c "%Y" "$UPDATE_DIR"/daily.cvd)
# This file extension name maybe change to .cvd or .cld
VIRUSTIME=$(stat -c "%Y" "$UPDATE_DIR"/daily.*)
INTERVALTIME=$((${NOWTIME}-${VIRUSTIME}))
echo ${INTERVALTIME}
if [ "${INTERVALTIME}" -ge 604800 ];then
crit "Database file has a date older than seven days from the current date"
FNRET=3

View File

@ -18,7 +18,7 @@ KEYWORD='promisc'
# This function will be called if the script status is on enabled / audit mode
audit () {
COUNT=$(ip link | grep -ic "${KEYWORD}")
COUNT=$(ip link | grep -i "${KEYWORD}" | wc -l)
if [ $COUNT -gt 0 ]; then
crit "The total number of network interfaces with ${KEYWORD} mode set is ${COUNT}"
FNRET=1