detect clamav scan install across linux os

Hello all. I need to detect if ‘clamav’(clamscan) is installed. Also, I need to test for it across linux os. I think I can use ‘$?’(status of command) to detect it. http://www.cyberciti.biz/faq/shell-how-to-determine-the-exit-status-of-linux-and-unix-command/ Is this the most effective method?

As that article explains clear enough, return value of 127 is given by the shell if the command can not be found by the shell. I doubt that that is the same as if something of the same name is “installed”. Even the exact definition of “installed” might have to be determined here.

But it may be that the fact that the shell, in the circumstances you invoked the shell and then invoked the command, returns 127 or different might satisfy your needs. That is up to you.

You can check the same (if the shell can find the command), with

which command

with might be better because it will check without executing the command if it is found.

To do what you likely want to do,

  • You need to determine what you want to do in each distro. Look for a specific package? Run a test command (like something like “clam --help” and test whether it returns null or not?) Or, in some recent scripts I’ve written I just run the install commands, if it’s already installed the package manager for that distro will just skip, else the package will be installed.
  • You need to detect the distro so you can then execute the appropriate commands for the detected distro.

I can’t help you too much with the first point, you’ll need to figure that out for yourself. The two approaches I describe next should work equally well to satisfy the second point but YMMV.
If you want to see an example of what I described about the package manager skipping over anything that is already installed, see the scripts you can download from this page

https://en.opensuse.org/User:Tsu2/openstack-install

First, the code from the current vmware-tools-patches repo

https://github.com/rasa/vmware-tools-patches/blob/master/setup.sh

And also some older code I proposed long ago (which works in its own way)

https://github.com/putztzu/vmware-tools-patches/blob/master/patched-open-vm-tools.sh

Note that both code snippets largely work with how distros conventionally make themselves identifiable. Rolling distros like openSUSE Tumbleweed and Debian’s Factory release use a different naming convention so may not work (additional code is required like what I provide in my Wiki page on zypper).

TSU

You might want to take a look at a number of articles I’ve posted on my Wiki
https://en.opensuse.org/User:Tsu2

There are a number of scripts including

  • An online real time script builder, so that your BASH scripts can be built quickly with minimal errors.
  • Identifying distro to run scripts appropriate for that distro (including working install examples for zypper, apt, yum)
  • Identifying Tumbleweed vs other “stable” openSUSE distro versions
  • When you’re building on an interactive script, how to automatically answer so that the script becomes automatic (non-interactive) without installing special apps to do so. This also might avoid completely re-writing functionality using APIs.
  • Various common zypper commands, particularly what you need for non-interactive installs

That’s off the top of my head… and only to date…

TSU

I’ll keep all that in mind for later. For now, these are the simplest ways to check for a command

which clamscan > /dev/null 2>&1
command_present=$?

clamscan --help > /dev/null 2>&1
command_present=$?


Then check for a non-zero status. Right?

I guess the question is, if you test for whether clamscan is installed, what do you intend to do if it’s not installed, simply quit and tell the User to install clamscan?

If you instead intend to install clamscan for the User, then there is no point in testing for whether it’s installed…
You should just skip that and run the install… If clamscan already exists (and likely latest), then the package manager will note it’s installed and skip on to whatever is next.

If you have a virtual machine running openSUSE, see for yourself what happens when you run the first Devstack script.
Run it the first time, and it will likely find a number of dependencies are missing (and maybe some already installed) so will install whatever is necessary.
Now, after running that script once, go ahead and run it again. The script will find all the dependencies are already installed so will then skip on to whatever is next.

TSU

I had a --setup option to install it. I want to be a simpler install and less instructions:

1a> In GUI, open terminal in ‘home/bin’.
or 1b> (cd home folder/bin) cd;cd bin
2> ‘touch scanvirus’
3> In open scanvirus for edit.
4> Paste in code, save, and exit.
5> ‘chmod +x scanvirus’
7> ‘scanvirus --help’

Yes, I can just test for it first. If it’s not installed, exit and ask the user to install it through their package manager. That keeps the script general enough for almost all linux destros. However, I can print out the install line opensuse, if they want to copy and paste it.

dependencies: (should be only one)

clamscan

http://linux.die.net/man/7/udisks Standard command?

printf is a perl command? I can convert that to echo. If it’s not standard?

I’ll check that Devstack script.

Downloadable?

FYI, right now, I’m still have very limited access to my computer.

No, don’t download the original devstack project files(My scripts do that, and properly execute, there are some tricky “su” and “sudo” due to permissions and paths issues).
Download and inspect <my> scripts which should clearly illustrate the concept of installing packages and dependencies on openSUSE, they’re fully documented (comments) so anyone should be able to understand the flow and what is being done with each line.

The instructions are on the page
https://en.opensuse.org/User:Tsu2/openstack-install

and the links to the scripts are in the section “Install Details”

No one script I’ve posted will be “the” answer to a number of things you’re doing in your own script, but a number of my scripts should suggest what I believe are optimal ways of doing things (Yes, I always welcome new ideas if someone thinks they can do something better another way).

I’d also ask whether you have a reason for going through all those steps to create a script, if the code is standard or nearly so for every User I would think that it’s far better to just create the script, store it somewhere (It’s free to post script files on openSUSE ang github for instance) for people to download.

TSU

Thanks for the info, I need time to look over them to fully understand the scripts.

This is a function to check commands using a simple method.

command_check ‘clamscan’ ‘udisks’ ‘printf’

command_check=
{
#step though command args
for command
do
tmpcmd=“$command”
tmpcmd+=" --help > /dev/null 2>&1"
eval “$tmpcmd”

   if  ! $? ]
      echo -e "$command not found.

"
fi
done
}

I’d also ask whether you have a reason for going through all those steps to create a script, if the code is standard or nearly so for every User I would think that it’s far better to just create the script, store it somewhere (It’s free to post script files on openSUSE ang github for instance) for people to download.

I’ll keep that location in mind. However, it still has too many problems I need to fix first (beta1, 2, and soon beta3). Such as, printing out the file name (during scan) to show what it’s doing is worthless, not to mention the line glitch. :stuck_out_tongue: I’v figured how to make an active file counter. How many the folders and all sub-folders can be done with find and wc. I have to match that value with what clamscan outputs on it’s scan. Keep in mind I use this myself all the time, being both coder and user. :slight_smile:

Thank for the help all. Now, I have many options to choose from. :slight_smile: