#!/bin/sh # path to an empty dummy test file testfile="/usr/local/directadmin/scripts/custom/clamav.txt" # path to the clamav database files without the ending "/" dbfolder="/usr/share/clamav" # path to the clamdscan executable scan="/usr/bin/clamdscan" # path to the freshclam executable freshdb="/usr/bin/freshclam" # number of times the script tries to kick start clamd trial=10 # email of server administrator email="user@domain.com" # server hostname (no modification needed) myhost=$(hostname) # email alert subject on failure subject="Clamd on ${myhost} is down!" # email alert body message on failure message="Clamd on ${myhost} is down!" output=$($scan $testfile | grep "SCAN SUMMARY") if [ -z "$output" ]; then echo "Clamd is not running!" echo "Now trying to start clamd..." for (( i=1; i<=$trial; i++ )) do echo "Trial $i..." /sbin/service clamd restart output=$($scan $testfile | grep "SCAN SUMMARY") if [ -n "$output" ]; then break else sleep 3 fi done if [ -z "$output" ]; then echo "Clamd is still not running!" echo "Now trying to refresh clamav database..." rm -Rf $dbfolder/* $freshdb /sbin/service clamd restart output=$($scan $testfile | grep "SCAN SUMMARY") if [ -z "$output" ]; then echo "Clamd is still not running!" echo "$message" | mail -s "$subject" "$email" echo "Giving up... email alert has been sent to administrator." else echo "Clamd is running now!" fi else echo "Clamd is running now!" fi else echo "Clamd is running!" fi