Solved Need help fixing old clamd running check script

Richard G

Verified User
Joined
Jul 6, 2008
Messages
13,935
Location
Maastricht
I got this somehwere, maybe from the site of Zeiter or somewhere else, but after the clamav change it does not work anymore and throws a "clamd service not running"

I already changed some binary paths, but I think for clamd it still is not correct.

Code:
#!/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="/var/lib/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="[email protected]"

# 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

I'm no coder. What I do see is this:
/sbin/service clamd restart

Now there is a /sbin/clamd present, however, the service is now called clam@scan and the other service is called clamav-freshlam and now I don't know which service needs to be checked.

Also the first part, checking if the clamd service is running, might not be correct.
However, the clamd service is running.

Code:
[root@server23: /sbin]# ps faux | grep clamd
clamscan 17003  0.1  2.1 1826380 1391496 ?     Ssl  00:16   1:24 /usr/sbin/clamd -c /etc/clamd.d/scan.conf

So probably the check if it running is wrong now.
I think somewhere the "if" statement or something which checks if clamd is running needs to be changed.

Can anyone help me fixing this?
 
The path changing seems to have fixed the check. However, the restart would never be good.

/sbin/service clamd restart
will cause:
Code:
[root@server23: /sbin]# /sbin/service clamd restart
Redirecting to /bin/systemctl restart clamd.service
Failed to restart clamd.service: Unit not found.

because the service is now called [email protected] and not clamd.service anymore.
 
Hmz... also looks like we might not need this script anymore. Because now the Fresclam and Clamav service is monitored in the DA service monitor too.
 
Back
Top