From Pine View Farm

Adventures in Linux: Automating a Virus Scan (Updated) 0

From time to time I scan for viruses and other malware with AVG for Linux. I decided to automate the process, so I wrote a script to scan my home folder and save the results of the scan to my home folder. If this works, I’ll see about automating a weekly scan for the entire computer (a complete scan takes several hours, because it also scans my 250 GB external hard drive).

Here’s what the script does:

    1. Declare a variable (“$NOW”) to give the report file a unique name and store it in a unique location.

    2. Make a directory to hold the report.

    3. Start the scan.

    4. Save the report to the selected directory.

The scan command parses as follows:

    avgscan=scan

    -r/home/[username]l/AVG/$NOW/scan$NOW.txt=save the report to this directory with this file name.

    /home/[username]=scan this directory (folder)

“Echo” means to display a line of text in a terminal.

Here’s the script:

#!/bin/bash

#Set the variable NOW

NOW=1

#Define now as today’s year-month-date-hour-minute.

NOW=$(date +%Y-%m-%d-%H-%M)

echo “Now = $NOW”

#Make the directory to hold the backup file.

mkdir /home/[username]/AVG/$NOW

echo “Making the directory ~/AVG/$NOW for the backup.”

#run scan home folder

echo “Scanning your home folder”

avgscan -r/home/[username]/AVG/$NOW/scan$NOW.txt /home/[username]/

echo “Scan completed and report saved.”

The script works. Then I put this line in my crontab file

* 2 * * * /home/[username]/scripts/vscan.sh

so that the scan will run automatically at 2 a. m. every morning.

I also put a line in my root crontab to update the virus scanner every morning at 1 a. m.

* 1 * * * /usr/bin/avgupdate

We’ll find out tomorrow whether the cron job runs.

Addendum:

I have some trouble to shoot.

The cron job ran. And ran. And ran. There were multiple instances of the script still running this morning. I’ve added “exit” to the end of the script and will see what happens the next time it runs.

Share

Comments are closed.

From Pine View Farm
Privacy Policy

This website does not track you.

It contains no private information. It does not drop persistent cookies, does not collect data other than incoming ip addresses and page views (the internet is a public place), and certainly does not collect and sell your information to others.

Some sites that I link to may try to track you, but that's between you and them, not you and me.

I do collect statistics, but I use a simple stand-alone Wordpress plugin, not third-party services such as Google Analitics over which I have no control.

Finally, this is website is a hobby. It's a hobby in which I am deeply invested, about which I care deeply, and which has enabled me to learn a lot about computers and computing, but it is still ultimately an avocation, not a vocation; it is certainly not a money-making enterprise (unless you click the "Donate" button--go ahead, you can be the first!).

I appreciate your visiting this site, and I desire not to violate your trust.