LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Is there a good way to find the OS version number? (http://www.linuxquestions.org/questions/linux-general-1/is-there-a-good-way-to-find-the-os-version-number-239570/)

BrianK 10-06-2004 05:50 PM

Is there a good way to find the OS version number?
 
I've got 14 machines running 3 OS's - RH7.3, RH9, Sus9.1. The RH9 & Suse9 machines can run the same executables, but the RH7.3 machines cannot run the same as the RH9 & Suse9 machines.

I'm trying to write a script that runs on each machine & points that machine to the correct executables (in shared space) based on the OS version. The only way I know how to get the version is rpm -qa | grep release (or something like that) & then do some if statements to see what matches.

While this will work, it's slow & not very elegant. Is there a better way of getting the version number? I'd love it if I could get just "7.3" or, even better, "7" when I ask for something like "major release" - that way, I could use the return of the command in the path to the executables - i.e. /shared/`find major-release`/dir/. Does something like this exist?

Samsara 10-06-2004 05:52 PM

man nmap

HTH,

Samsara

Tinkster 10-06-2004 06:10 PM

Re: Is there a good way to find the OS version number?
 
Quote:

Originally posted by BrianK
I've got 14 machines running 3 OS's - RH7.3, RH9, Sus9.1. The RH9 & Suse9 machines can run the same executables, but the RH7.3 machines cannot run the same as the RH9 & Suse9 machines.

I'm trying to write a script that runs on each machine & points that machine to the correct executables (in shared space) based on the OS version. The only way I know how to get the version is rpm -qa | grep release (or something like that) & then do some if statements to see what matches.

While this will work, it's slow & not very elegant. Is there a better way of getting the version number? I'd love it if I could get just "7.3" or, even better, "7" when I ask for something like "major release" - that way, I could use the return of the command in the path to the executables - i.e. /shared/`find major-release`/dir/. Does something like this exist?

That "major_release" is not all that different from your
first idea ;) ... rpm -qa on a fast machine should be easy
and quick enough, too.

I currently can't get my hands on a SuSE machine, but
it may well be that there's a /etc/suse-version file ...
there's one on redhat (/etc/redhat-release) which would
make the parsing quite simple.


Cheers,
Tink

BrianK 10-06-2004 06:17 PM

Re: Re: Is there a good way to find the OS version number?
 
Quote:

Originally posted by Tinkster
That "major_release" is not all that different from your
first idea ;) ... rpm -qa on a fast machine should be easy
and quick enough, too.

I currently can't get my hands on a SuSE machine, but
it may well be that there's a /etc/suse-version file ...
there's one on redhat (/etc/redhat-release) which would
make the parsing quite simple.

ahh.. Thanks Tink. There is, in fact, /etc/SuSE-release on the Suse box.

Not quite as spoon fed as I'd like to be, but I can work with this. Thanks!

Tinkster 10-06-2004 06:22 PM

awk '{for(i=1; i <= NF;i++){if( $i ~ /[0-9]/) print $i}}' /etc/*version* | cut -d. -f 1

I'm sure there's an easier way of getting that :}


Cheers,
Tink

BrianK 10-06-2004 06:37 PM

Quote:

Originally posted by Tinkster
awk '{for(i=1; i <= NF;i++){if( $i ~ /[0-9]/) print $i}}' /etc/*version* | cut -d. -f 1

I'm sure there's an easier way of getting that :}

the uncharted territory of "awk" - looks interesting.

Thanks again!

Tinkster 10-06-2004 10:54 PM

You're welcome ;)

Feel free to affero me if this helped :)


Cheers,
Tink


All times are GMT -5. The time now is 07:52 PM.