Skip to content

Instantly share code, notes, and snippets.

@kainjinez
Created February 8, 2021 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kainjinez/1b46ccb9783361d1715e830dde9ecb6e to your computer and use it in GitHub Desktop.
Save kainjinez/1b46ccb9783361d1715e830dde9ecb6e to your computer and use it in GitHub Desktop.
DirectAdmin ClamAV test running state
#!/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/local/share/clamav"
# path to the clamdscan executable
scan="/usr/local/bin/clamdscan"
# path to the freshclam executable
freshdb="/usr/local/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment