CLAMAV STARTUP and UPDATE SCRIPT

Posted: October 21, 2008 in SENDMAIL
Tags:
  • Create the signature-updater script
  • cat > clamav_update << "EOF"
  • #!/bin/sh
    /usr/local/bin/freshclam –quiet –stdout –datadir /usr/local/share/clamav –log /var/log/clamav/clam-update.log
    EOF
  • make the script executable
    • chmod 700 clamav_update
  • copy the script to /etc/cron.hourly or create an entry in cron
  • execute the script to update the software
  • create a startup script (/etc/rc.d/clamav)
    • #!/bin/sh
      
      FOO_BIN=/usr/sbin/clamd
      test -x $FOO_BIN || exit 5
      
      case "$1" in
          start)
      	echo "Starting `$FOO_BIN -V`"
      	$FOO_BIN
      
      	;;
          stop)
      	echo "Shutting down `$FOO_BIN -V`"
      	killall $FOO_BIN
      
      	;;
          restart)
      	$0 stop
      	$0 start
      
      	;;
          *)
      	echo "Usage: $0 {start|stop|restart}"
      	exit 1
      	;;
      esac
    • Another Clamav startup script

    create an init script for ClamAV (/etc/init.d/clamd):

    #!/bin/bash
    
    TMPDIR=/tmp
    PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
    
    case "$1" in
        start)
            echo "Starting ClamAV..."
            if [ -S /tmp/clamd ]; then
              echo "ClamAV is already running!"
            else
              /usr/local/bin/freshclam -d -c 10 --datadir=/usr/local/share/clamav
              /usr/local/sbin/clamd
            fi
            echo "ClamAV is now up and running!"
        ;;
        stop)
            echo "Shutting down ClamAV..."
            array=(`ps ax | grep -iw '/usr/local/bin/freshclam' | grep -iv 'grep' \
    		       | awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
            element_count=${#array[@]}
            index=0
            while [ "$index" -lt "$element_count" ]
            do
              kill -9 ${array[$index]}
              let "index = $index + 1"
            done
            array=(`ps ax | grep -iw '/usr/local/sbin/clamd' | grep -iv 'grep' \
    		       | awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
            element_count=${#array[@]}
            index=0
            while [ "$index" -lt "$element_count" ]
            do
              kill -9 ${array[$index]}
              let "index = $index + 1"
            done
            if [ -S /tmp/clamd ]; then
              rm -f /tmp/clamd
            fi
            echo "ClamAV stopped!"
        ;;
        restart)
            $0 stop  && sleep 3
            $0 start
        ;;
        *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
    esac
    exit 0

    chmod 755 /etc/init.d/clamd

    Now we start ClamAV:

    /etc/init.d/clamd start

    you will now notice some clamd processes (which use the socket /tmp/clamd) and a freshclam process which is responsible for getting the newest virus signature updates. They are located under /usr/local/share/clamav. The command

    /usr/local/bin/freshclam -d -c 10 –datadir=/usr/local/share/clamav

    in our clamd init script makes sure that freshclam checks for new signatures 10 times per day.

    In order to start ClamAV at boot time do the following:

    ln -s /etc/init.d/clamd /etc/rc2.d/S20clamd
    ln -s /etc/init.d/clamd /etc/rc3.d/S20clamd
    ln -s /etc/init.d/clamd /etc/rc4.d/S20clamd
    ln -s /etc/init.d/clamd /etc/rc5.d/S20clamd
    ln -s /etc/init.d/clamd /etc/rc0.d/K20clamd
    ln -s /etc/init.d/clamd /etc/rc1.d/K20clamd
    ln -s /etc/init.d/clamd /etc/rc6.d/K20clamd

      Advertisements

      Leave a Reply

      Please log in using one of these methods to post your comment:

      WordPress.com Logo

      You are commenting using your WordPress.com account. Log Out / Change )

      Twitter picture

      You are commenting using your Twitter account. Log Out / Change )

      Facebook photo

      You are commenting using your Facebook account. Log Out / Change )

      Google+ photo

      You are commenting using your Google+ account. Log Out / Change )

      Connecting to %s