Add right-click virus scanning capability to Nautilus
Below is simple example on how to scan any file right in Nautilus via the right click menu. Enjoy.
- sudo apt-get install (or yum/zypper/pacman, etc.) clamav
- vim ~/.gnome2/nautilus-scripts/virus-scan
- Paste the following in the file:
#!/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
4. chmod 755 ~/.gnome2/nautilus-scripts/virus-scan







