Hello all. I finally fixed the space in partition name bug and the unmount bug. I’v added new features and design improvements.
“scanvirus” is an script on top of clamscan to make virus scanning on windows and linux simpler and faster. It includes a current file count, improved logs, and virus vault storage. It requires clamscan and udisks2 installed, nothing else. However, there is one function hidden and will not be supported. It’s a shortcut to opening a kde window to view the logs, “scanvirus -vl”.
You can free modify the script for your own use, but don’t upload a modified version to any location.
Software License: https://creativecommons.org/licenses/by-nc-nd/4.0/
It uses a system folder for logs and this may cause problems. Please post here any conflicts.
Also, there was a website(s) where I could paste it. I can’t find the message. If you know where, please post here.
Here’s are the checksums for the file I have. Copy and paste in file. Press enter on last line and save. Follow instructions in file.
md5sum scanvirus
123b06e9265c745e530bdf8822702bc0 scanvirus
sha512sum scanvirus
3ff163dec73aa7a17d68dff986c66f21de7f94ea6db053eb19daa673b0ef36b94eeef74758bb2fb43d277892fb1ea07158f52b2641e1195f75f20f732fad5b01 scanvirus
#!/bin/bash
#: Title : scanvirus
#: Date Created: Thu Sep 2 19:27:00 PST 2010
#: Last Edit : Tue Nov 29 2:07:00 PST 2016
#: Author : Lord Valarian #: Version : 2.0.0 beta3
#: Description : virus scanning application, clamscan engine
#Software License: https://creativecommons.org/licenses/by-nc-nd/4.0/
#Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
#NonCommercial — You may not use the material for commercial purposes.
#NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material.
#Bug fix: space in partition name
#upgrades: improved design
#Open bin folder
#Place this file inside "/home/bin/"
#
#Right-click on scanvirus
#Click on properties
#Click on permissions
#Check executable and click ok
#install clamav or run setup
#Click Control -> Tools -> Open Terminal
#Enter termal command: scanvirus --setup
#Enter admin password, wait for it to finish. Don't close terminal.
#kdeicon disabled (next build)
#Enter terminal command: scanvirus --kdeicons
#close terminal windows
#
#Click on either desktop icon to scan
#Warning! only use control-c to exit
Create_KDE_linux_scan_icon() {
cat > ScanVirus_KDE_Linux_Scan.desktop <<EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Comment[en_US]=
Comment=
Exec=sh scanvirus -linux
GenericName[en_US]=
GenericName=
Icon=kde
MimeType=
Name[en_US]=ScanVirus - linux anti-virus scan
Name=ScanVirus - linux anti-virus scan
Path=$PATH
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
X-SuSE-translate=trueEOF
EOF
#set file permissions
chmod 744 ScanVirus_KDE_Linux_Scan.desktop
}
Create_KDE_windows_scan_icon() {
cat > ScanVirus_KDE_Windows_Scan.desktop <<EOF
#!/usr/bin/env xdg-open
[Desktop Entry]
Comment[en_US]=
Comment=
Exec=sh scanvirus -mswin
GenericName[en_US]=
GenericName=
Icon=kde
MimeType=
Name[en_US]=ScanVirus - windows anti-virus scan
Name=ScanVirus - windows anti-virus scan
Path=$PATH
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
X-SuSE-translate=true
EOF
#set file permissions
chmod 744 ScanVirus_KDE_Windows_Scan.desktop
}
Virus_Vault_Directory_Check()
{
#create var directory if not present
if [ -d "/var" ]; then
printf "root--> /var/ directory present
"
else
printf "creating var directory
"
mkdir var
#chmod 744
fi
#create log directory if not present
if [ -d "/var/log" ]; then
printf "root--> /var/log/ directory present
"
else
printf "creating log directory
"
mkdir /var/log
#chmod 744
fi
#create virus Vault if not present
if [ -d "/var/log/VirusVault" ]; then
printf "root--> /var/log/virusvault/ present
"
else
printf "creating virus vault
"
mkdir /var/log/VirusVault
chmod 744 /var/log/VirusVault
fi
Virus_Vault_Folder='/var/log/VirusVault'
}
Scan_Results_Filter()
{
ScanLine=''
filecount=0
delete_line_flag=true
scan_results_flag=false
IFS=''
while read -r ScanLine; do
if [ "$scanvirus_trap_flag" = 'true' ];then
break
fi
#get filescan results
Scanfile_Results=${ScanLine##*:}
#printf "ScanLine= %s
" $ScanLine
#printf "Scanfile_Results= %s
" $Scanfile_Results
if [ "$delete_line_flag" = 'true' ]; then
echo -en "\E[2K\r"
delete_line_flag=false
fi
#if scan summary then stop deleting lines
if [ "$ScanLine" = '----------- SCAN SUMMARY -----------' ]; then
#printf "filecount= %i
" $filecounter
scan_results_flag=true
fi
if [ "$scan_results_flag" = 'true' ]; then
printf "%s
" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
elif [[ "$ScanLine2" == *"Symbolic"* ]];then
printf "%s
" $ScanLine
elif [[ "$Scanfile_Results" == *"FOUND"* ]];then
let filecounter=filecounter+1
printf "%s
" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
elif [[ "$Scanfile_Results" == *"MOVED TO"* ]];then
printf "%s
" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
elif [[ "$Scanfile_Results" == *"OK"* ]] || [[ "$Scanfile_Results" == *"EMPTY"* ]] ;then
let filecounter=filecounter+1
printf "%i" $filecounter
delete_line_flag=true
fi
done
unset IFS
}
scanvirus_trap_flag=false
control_c()
# run if user hits control-c
{
#scanvirus_trap_flag=true
#if drive mounted, unmount it
#printf "Device_Mounted_Flag = %s Device_Label= %s
" $1 $2
if [ "$1" = 'true' ];then
command_output_unmount=$(udisksctl unmount -b "$2");unmount_error=$?
printf "%s
" $command_output_unmount
fi
printf 'exiting...
'
}
#read -p "Done. Press any key..." -n1 -s;printf "";
#####################
# shortcut code for clamscan #
#####################
# if not in superuser mode
if [[ $EUID -ne 0 ]]; then
printf "--- superuser/root only ---
"
exit 1
fi
# if clamscan not installed
clamscan --help > /dev/null 2>&1
if [[ $? = 127 ]]; then
echo "clamscan not installed" 1>&2
exit 1
fi
# if clamscan not installed
udisksctl > /dev/null 2>&1
if [[ $? = 127 ]]; then
echo "udisks2 not installed" 1>&2
exit 1
fi
#export TERM=vt100
Virus_Vault_Directory_Check;
freshclam
#commands
if [ "$1" = "-mswin" ] || [ "$1" = "-w" ]; then
Current_Vault_Folder="$Virus_Vault_Folder/MSWIN "
Current_Vault_Folder+=$(date)
mkdir "${Current_Vault_Folder}"
printf "
.....scanvirus mswin.....
" | tee "$Current_Vault_Folder/scanresults.log"
IFS=':'
blkid | sed 's/: /:/g' | sed 's/\" /:/g' | while read -ra line
do
Device_Label=''
File_System=''
Drive_Label=''
Mount_Point=''
Device_Label=${line[0]}
for blkid_field in ${line
[li]}[/li] do
if [[ "$blkid_field" == "TYPE="* ]];then
#cut 'type='
File_System=${blkid_field#*\"}
elif [[ "$blkid_field" == *"LABEL="* ]];then
#cut 'label='
Drive_Label=${blkid_field#*\"}
fi
done
#cut /dev/
Temp_MP=${Device_Label#/*/} #printf "Temp_MP= %s
" ${Temp_MP}
# cut devicename
Mount_Point=$( lsblk -l -o name,mountpoint | grep "${Temp_MP}" | sed "s/${Temp_MP} //g" )
#if file system vfat or ntfs
if [ "$File_System" = 'ntfs' ] || [ "$File_System" = 'vfat' ]; then
if [ "$Drive_Label" = "System Reserved" ]; then
#printf "Skipping System Reserved...
"
continue
fi
printf "__________________________________________________
" | tee -a "${Current_Vault_Folder}/scanresults.log"
#printf "Device_Label= \'%s\'
" $Device_Label
#printf "File_System= \'%s\'
" $File_System
#printf "Drive_Label= \'%s\'
" $Drive_Label
#printf "Mount_Point= \'%s\'
" $Mount_Point
#printf "
"
Device_Mounted_Flag=false
#if device not mounted
if [ "$Mount_Point" = '' ]; then
command_output_scandir=$(udisksctl mount -b "$Device_Label");mount_error=$?
command_output_scandir=${command_output_scandir%.}
printf "%s
" $command_output_scandir
#cut out scan directory
command_output_scandir=${command_output_scandir#Mounted\ *\ at\ }
Mount_Point=$command_output_scandir
#printf "%s
" $Mount_Point
if [ "$mount_error" != 0 ]; then
printf "Error: mount %s
" $Drive_Label
else
Device_Mounted_Flag=true
fi
fi
printf "
scanning: %s %s
" $Drive_Label $Mount_Point | tee -a "${Current_Vault_Folder}/scanresults.log"
# trap keyboard interrupt (control-c)
trap "control_c $Device_Mounted_Flag $Device_Label" exit
#scan only or move files
if [ "$2" = "-m" ] || [ "$2" = "-movetovault" ]; then
printf "Move to Virus Vault: /var/log/VirusVault/
"
clamscan -r "$Mount_Point" "--move=${Current_Vault_Folder}" --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
else
printf "Scan only
"
clamscan -r "$Mount_Point" --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
fi
#printf "movefile_parm= %s
" $Movefile_Parm
#break
#if drive mounted, unmount it
if [ "$Device_Mounted_Flag" = 'true' ];then
command_output_unmount=$(udisksctl unmount -b "$Device_Label");unmount_error=$?
printf "%s
" $command_output_unmount
fi
printf "__________________________________________________
" | tee -a "${Current_Vault_Folder}/scanresults.log"
fi
#break
if [ "$scanvirus_trap_flag" = 'true' ]; then
break
fi
done
#virus vault files read only
#chmod 744 "${Current_Vault_Folder}"
elif [ "$1" = "-linux" ] || [ "$1" = "-l" ]; then
Current_Vault_Folder="$Virus_Vault_Folder/linux "
Current_Vault_Folder+=$(date)
mkdir "${Current_Vault_Folder}"
printf ".....Scanning linux.....
" | tee "${Current_Vault_Folder}/scanresults.log"
clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --exclude-dir=/.snapshots --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
printf "__________________________________________________
" | tee -a "${Current_Vault_Folder}/scanresults.log"
elif [ "$1" = "-viewlogs" ] || [ "$1" = "-vl" ]; then
kdesu dolphin /var/log/VirusVault/
elif [ "$1" = "-help" ] || [ "$1" = "-h" ]; then
printf "
Scan Virus
help commands
-------------
virus scan linux files
p1: -l or -linux
virus scan windows files
p1: -w or -mswin
p2: -m or -movetovault (optional)
--setup: install clamscan
--kdeicons: setup icons (disabled)
"
elif [ "$1" = "--setup" ]; then
printf "
"
printf "ScanVirus Setup...
"
zypper --non-interactive install clamav;chkconfig freshclam on;freshclam;exit
printf "
"
elif [ "$1" = "--kdeicons" ]; then
#Create_KDE_linux_scan_icon;
#Create_KDE_windows_scan_icon;
#printf "KDE Icons Created
";
printf "Disabled
";
else
printf "
Scan Virus
help commands
-------------
virus scan linux files
p1: -l or -linux
virus scan windows files
p1: -w or -mswin
p2: -m or -movetovault (optional)
--setup: install clamscan
--kdeicons: setup icons (disabled)
"
fi
exit 0
# End Of Script