Informations, tips and technics.

Checking OS version on Linux or Unix

I work right now on a bash script utility and I have tried to find a way to check what is my system. The goal of the script is to runs some commands and can be run on RedHat, Suse Linux and Solaris.

I have use this code :

for base in `ls /etc/*release*` ; do
    if [ -f “$base” ]; then
z=$(cat $s | tr [a-z] [A-Z])
id=${z// /}
for critere in $cri; do
    rd=`expr match “$id” “$critere”`
  if [ ! “$rd” -eq 0 ]; then

Assuming that you have a release file in /etc then it should works.

If you are going to ask me why I do not use a findfunction to retrieve all the files in /etc it is because the version of findin Linux and Solaris does not have the same parameters and I can’t use the-maxdeph 1 method to search only in /etc.

So I ended up using an ls function and then test is the result is really a file or not (I do no manage folders and symbolic links). If it is then I can proceed some checks.

Maybe not the best code to know what can of the system the script in running onto but well, it works. But feel free to comment!


Filed under: Bash, Linux

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: