clamscan one-click virus scan

Suse 11.3 64

klamav KDE doesn’t work. It won’t download updates. So, I want to make a one-click scan. I’v been using shell installers from nvidia. I know the sequence I use in the terminal to get it running. There should be way to do this from the desktop.

cd ..
cd ..
su
freshclam
clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev

How do I do that? Thanks.

Why not consider writing a bash script file for what you need? Look at my thread called:

N.S.F. - New Script File Header Creator

So I ran the command “nsf cs” in the terminal mode and then copy/pasted the information from your message (with modifications) and ended up with an executable script file called cs located in the user ~/bin folder. To use this script without using nsf, don’t forget to make the script file executable.

#!/bin/bash

#: Title       : /home/lord_valarian/bin/cs
#: Date Created: Thu Sep 2 19:27:00 CDT 2010
#: Last Edit   : Thu Sep 2 19:27:00 CDT 2010
#: Author      : lord_valarian
#: Version     : 1.00
#: Description : Run virus scanning application
#: Options     : None


if  "$HOME" == "/root" ] ; then
   sudo $0
fi

cd ..
cd ..
freshclam
clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev

exit 0
# End Of Script

Then to create a shortcut to the script file on the desktop I right clicked on the desktop and selected Create New / Link To Application.Go to the Application Tab and enter the command of cs. Select the advanced button and elect to run in Terminal. Finally Go to the General Tab and changed the name to ClamScan, or anything you like and pick OK. To change the icon, right click on the new desktop icon and pick properties. Select the default icon and make it anything you like as well.

Now you can run this automated terminal task anytime you want.

Thank You,

/bin/clamscan.sh

I use KDE desktop. I changed it to executable. It’s properties read as “shell script”. I click on it and nothing happens. There is no “link to application” for right-click on desktop. I can drag a shortcut to the desktop. it to executable. It’s properties read as “shell script”. I click on it and nothing happens. There is no “link to application” for right-click on desktop. I can drag a shortcut to the desktop. Also, my system has massive slowdown after I click on it. So, I have to force a shutdown. (ctrl-alt-backspace). Sometimes, I have use the power switch on the case for motherboard shutdown.

So there are two parts to this. One is to create a usable script and the other is to put it on your desktop. To determine if the script is working, open up a terminal session (like konsole) and type the command:

clamscan.sh

Which you indicated is what you called your script file. You should be prompted to enter the root user password and then the script runs as you indicated you did it manually. If this works OK, the next step is to create an icon for it on your desktop. Let me know if part one works before we proceed with part two. If this does not work, then your script is not yet correct.

Thank You,


cd bin
sh clamscan

ERROR: Can't create temporary directory /var/lib/clamav/clamav-b825c126a194c7bec7724a00a438d6aa
Hint: The database directory must be writable for UID 1000 or GID 100
ERROR: Can't create temporary directory /var/lib/clamav/clamav-126162c39e65450c198708f17037111a
Hint: The database directory must be writable for UID 1000 or GID 100
ERROR: Can't create temporary directory /var/lib/clamav/clamav-dada6fecef11b3df71e5ce5517c50ea5

Repeats

Instead of typing this:

cd bin
sh clamscan

Type this instead:

clamscan.sh

Which you indicated was the name of your script. Also, the ~/bin folder is in your path and so you do not need to change to it.

Thank You,

My scriptname is the same as a command in the script(duh). So, I renamed the file to “scanvirus”. Now I get:

> scanvirus
ERROR: Can't create temporary directory /var/lib/clamav/clamav-54a27b15cf285d81820b744129d5e73c
Hint: The database directory must be writable for UID 1000 or GID 100
/lost+found: Can't open directory.
/bin/pgrep: OK
/bin/fsync: OK
/bin/md5sum: OK
/bin/sed: OK

continues, no prompt for su password.

So, lets change the following line which read:

if  "$HOME" == "/root" ] ; then
   sudo $0
fi

To this new code:

if  "$HOME" != "/root" ] ; then
   sudo $0
fi

and run this in a normal terminal session, not started as root as see what we get.

Thank You,

#!/bin/bash

#: Title       : /home/lord_valarian/bin/cs
#: Date Created: Thu Sep 2 19:27:00 CDT 2010
#: Last Edit   : Thu Sep 2 19:27:00 CDT 2010
#: Author      : lord_valarian
#: Version     : 1.00
#: Description : Run virus scanning application
#: Options     : None


if  "$HOME" != "/root" ] ; then
   sudo $0
fi

cd ..
cd ..
freshclam
clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev

exit 0
# End Of Script

It works. :slight_smile: Now I need get it so only a super user can alter the script in case someone hacks my user account. Still does nothing when I click on the shell script.

Also, it seems i’v stumbled onto recursive scripts. Has anyone else used this? Else, i’m the first. For suse techs, this has the potential to be a virus, given what this did to my system. This should be looked into asap.

Well, when the script is written right the first time, it can only be run if you know the root user password. When we started, I could not run it myself since I do not have the virus scanner loaded, I made a script logic error and you did not realize the script name should be different from everything else. As for creating an icon on your screen, that will also work, trust me on this. Reread those instructions I gave, knowing the correct name of the script file this time.

Thank You,

 There is no "link to application" through the desktop. I found it in the dolphin file menu(File->New->link to application). In properties, I checked "executable", "run in terminal", "don't close on exit". Now, I did left-click drag(link to script) to the desktop and open properties. I changed the icon to KDE. It works now. Maybe I can find a good anti-virus icon.  :)

Thanks, how do I make the script so it only be changed by admin? In my user account gets broken into.

So go to the KDE menu / System / File Manager / File Manager - Super User Mode and enter the root user password. Go to the bin folder where the script file is saved, right click on it and pick properties. Go to the Permissions Tab and change the User to root and the Group to root and press the OK button. Then, only the root user can modify (and due to the way the script is written) or run this script file, though a standard user could start it, but it will fail if you do not know the root user password. Don’t make this final change until all is correct with the script for you as you will have to reverse this process to edit the file again or you must run the editor from within the Super User File Manager mode.

Thank You,

Before I do that, I need a command line option. “-w” will scan the windows directories only. Scanning takes long time, but I still need the option.

If parm1 == “-w”
clamscan -r --include-dir=windows
else
clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev
fi

Moving infected files is easy(–help), but how do I create the dir if it’s not there within the script. Say put them into: home/infected/

Try this modified code.

If  "$1" == "-w" ] ; then 
        clamscan -r --include-dir=windows
else 
        clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev
fi

Keep in mind I can not check it myself.

Thank You,

I got errors. I corrected them and added virus move.

#!/bin/bash

#: Title       : /home/lord_valarian/bin/cs
#: Date Created: Thu Sep 2 19:27:00 CDT 2010
#: Last Edit   : Thu Sep 2 19:27:00 CDT 2010
#: Author      : lord_valarian
#: Version     : 1.00
#: Description : Run virus scanning application
#: Options     : None


if  "$HOME" != "/root" ] ; then
   sudo $0
fi

cd ..
cd ..
freshclam

if  "$1" == "-w" ];
then 
        clamscan -r --include-dir=windows --move=/home/bin/virus-vault;
else 
        clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --move=/home/bin/virus-vault;
fi

exit 0
# End Of Script

ERROR: ‘/home/bin/virus-vault’ doesn’t exist or is not a directory

You have that directory?? /home/bin/virus-vault seems a little odd but maybe you created it???

Yes I have to agree with gogalthorp, the folder /home/bin/virus-vault does not exist. You are going to need to create this folder before you can send files to it.

Thank You,

Yes, did. duh! :wink: Can the script detect if the directory isn’t there?

I still get that error.

OK, lets see how this looks. Remember, I can’t check this out on my computer.

#!/bin/bash

#: Title       : /home/lord_valarian/bin/cs
#: Date Created: Thu Sep 2 19:27:00 CDT 2010
#: Last Edit   : Thu Sep 9 18:23:00 CDT 2010
#: Author      : lord_valarian
#: Version     : 1.01
#: Description : Run virus scanning application
#: Options     : None

DIRECTORY="/home/bin/virus-vault"

# New Way to determine if being run as root
if  $UID -eq 0 ] ; then
   sudo $0
fi

cd ..
cd ..
freshclam

if  "$1" == "-w" ];then 
        clamscan -r --include-dir=windows --move=/home/bin/virus-vault;
else 
#
# The next clamscan command will only run if the folder $DIRECTORY exists
#
        if  -d "$DIRECTORY" ]; then
                  clamscan -r --exclude-dir=windows --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --move=$DIRECTORY;
        else
                  echo $DIRECTORY " Does Not Exist!"
        fi
fi

exit 0
# End Of Script

Thank You,

DIRECTORY="/home/$[username]/bin/virus-vault"

So, the username must be changed in the path so that any person can use it. Is there string for username I can put into the path?