Howto: command/tool ability check

harald asked:

When developing a shell script that should run on various unix/linux derivates, i sometimes have the problem that some tools have to be called in a different way compared to other systems. For example if the arguments are different. I wonder what’s the best way to solve this.

Should i use uname to check for the operating system name and rely on this to execute the tool in different ways or are there any “better” ways, some kind of “ability” check for shell commands and tools?

The systems in question are for example Linux, Mac OS X, Solaris and Irix — all quite different when it comes to abilities of tools and shell commands.

My answer:


You could use the facter tool which is part of Puppet (but can be used independently, if you don’t have Puppet in your environment) to get basic facts about the target system.

For instance:

$ facter operatingsystem
CentOS

$ facter kernel kernelversion osfamily
kernel => Linux
kernelversion => 2.6.32
osfamily => RedHat

gem install facter should be sufficient to install it on any system with Ruby available, if it’s not in your system packages already.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.