With this script saved in ~/.gnome2/nautilus-scripts, you can scan files or directories for viruses by simply right-clicking on them in Nautilus and selecting this script from the, "Scripts" dropdown menu. It relies on Clam Anti-virus which can be easily installed by doing, "sudo apt-get install clamav" in a shell. Simply copy the code below, into a text file and save it as, "virus-scan" and make it executable (ex: chmod 755 virus-scan). Again, it needs to be located in your ~/.gnome2/nautilus-scripts (dot in front of 'gnome2') directory. Anyway, here's the script:
#!/bin/bash
#
# Nautilus anti-virus scanner script v1.2 - Uses Clam Anti-virus
# Written by Robert Pectol, December 2005 - http://rob.pectol.com
#
# This program is free software. It is distributed in the hope
# that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
######################################################################
# Set some variables used in the script
files=$1
if [ "$NAUTILUS_SCRIPT_CURRENT_URI" == "x-nautilus-desktop:///" ]; then
files_path=$HOME"/Desktop"
else
files_path=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's/^file:\/\///'`
fi
gui=`which zenity`
vscan=`which clamscan`
# Function to scan file(s)
scan_it()
{
touch /tmp/scanresult
if [ "$files_path" = "" ]; then
# Script can run from launchers, scripts other than from Nautilus, etc. (doesn't require $NAUTILUS_SCRIPT_CURRENT_URI)
result=`$vscan -r "$files" --log=/tmp/scanresult | $gui --title "Virus Scanner" --progress \
--text="Scanning $files..." --pulsate --auto-close; cat /tmp/scanresult` &> /dev/null
else
result=`$vscan -r "$files_path/$files" --log=/tmp/scanresult | $gui --title "Virus Scanner" --progress \
--text="Scanning $files..." --pulsate --auto-close; cat /tmp/scanresult` &> /dev/null
fi
rm -f /tmp/scanresult &> /dev/null
# Feedback - if scan ended with errors or was terminated prematurely...
if [ "$result" = "" ]; then
err_text="Virus scan on $files terminated!"
errors
fi
# Feedback - if scan completed successfully...
clean=`echo $result | grep 'FOUND'`
# Alter gui feedback according to presense/absense of virus(s) found during scan
if [ "$clean" != "" ]; then
$gui --title "Virus Found!" --error --text="$result" &> /dev/null
else
$gui --title "Virus Scan Results!" --info --text="$result" & &> /dev/null
fi
}
# Function to handle errors
errors()
{
$gui --title "Virus Scan Error!" --error --text="$err_text" &> /dev/null
exit 1
}
# Check for presense of required utilities
if [[ -x "$vscan" && -x "$gui" ]]; then
scan_it
else
if [ -x "$vscan" ]; then
echo "Zenity was NOT found on the system!"
exit 1
else
err_text="Clam Anti-virus was NOT found on the system!"
errors
fi
fi
exit 0
Enjoy!