2016
-
05
-
22
09:01 pm
Entry tags:
bash
,
clamav
,
linux
,
script
ClamAV automated install
There are a few moving parts to getting ClamAV installed and set up correctly to scan weekly so I threw together a useful script that does it automatically on any redhat based machine.
#!/bin/bash DIRTOSCAN="/home /var/spool /bin /sbin"; SCANDIR=/opt/company/scans/ GREEN=$(tput setaf 2) RESET=$(tput sgr0) function clamav_install () { echo -e "${GREEN}Installing and configuring ClamAV antivirus${RESET}" echo "" yum -y install clamav yum -y install clamav-update echo -e "${GREEN}Creating scan directory /opt/phishlabs/scans${RESET}" echo "" mkdir /opt/phishlabs/scans change_clamav_config echo -e "${GREEN}Updating the virus signature database. (This could take some time)${RESET}" /usr/bin/freshclam } function setup_autoscan () { echo -e "${GREEN}Creating autoscan script${RESET}" cat >/opt/company/scripts/virscan.sh <<EOF1 #!/bin/bash /usr/bin/freshclam for i in $DIRTOSCAN; do /usr/bin/clamscan -rv $DIRTOSCAN > $SCANDIR$HOSTNAME.$(date +%y%m%d); done EOF1 chmod +x /opt/company/scripts/virscan.sh echo -e "${GREEN}Adding script to root crontab${RESET}" COMMENT="#This is the virus scan script from ClamAV" LINE="0 0 * * 0 /opt/phishlabs/scripts/virscan.sh" SPACE=" " (crontab -u root -l; echo "$COMMENT"; echo "$LINE"; echo "$SPACE" ) | crontab -u root - } function change_clamav_config () { echo -e "${GREEN}Changing configuration to allow DB update${RESET}" sed -i 's/Example/#Example/g' /etc/freshclam.conf sed -i 's/FRESHCLAM_DELAY=disabled-warn/#FRESHCLAM_DELAY=disabled-warn/g' /etc/sysconfig/freshclam } function main() { clamav_install setup_autoscan } main echo -e "${GREEN}ClamAV installed and configured successfully for automated scanning${RESET}" exit
[
Home
|
Post Entry
|
Log in
|
Search
|
Browse Options
|
Site Map
]