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.