OS Version

M

Mark J Fenbers

$^O gives the O/S name, in my case : 'linux', but I want to run my Perl script
on RH 7.X and RH 9.x of Linux. How can my script determine which version of the
O/S it is running on?

Mark
 
B

Ben Morrow

Mark J Fenbers said:
$^O gives the O/S name, in my case : 'linux', but I want to run my Perl script
on RH 7.X and RH 9.x of Linux. How can my script determine which version of the
O/S it is running on?

my $osvers = `uname -r`;

will return the OS version (at least on Linux). Note that this is the
kernel version, not the DeadRat distribution version.
[Attachment type=text/x-vcard, name=Mark.Fenbers.vcf]

DON'T do that.

Ben
 
J

Josef Möllers

Mark said:
$^O gives the O/S name, in my case : 'linux', but I want to run my Perlscript
on RH 7.X and RH 9.x of Linux. How can my script determine which version of the
O/S it is running on?

RedHat (and SuSE, don't know about the others) have a file /etc/*release
which tells you the version of the installed distribution.
Not that the contents is anything standard.

Josef
 
J

Jürgen Exner

Mark said:
$^O gives the O/S name, in my case : 'linux', but I want to run my
Perl script on RH 7.X and RH 9.x of Linux. How can my script
determine which version of the O/S it is running on?

But linux is the operating system, isn't it?
RHxyz is the distribution, and has little to do with the OS

jue
 
J

James Willmore

$^O gives the O/S name, in my case : 'linux', but I want to run my Perl script
on RH 7.X and RH 9.x of Linux. How can my script determine which version of the
O/S it is running on?

Why should your script care about the distro of Linux?

More importantly, why are you coding to a certain distro of Linux?
That a little like making tall kitchen garbage bags to fit only a certain
vendor's tall kitchen garbage can :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Are you a turtle?
 
M

Mark J Fenbers

Well, because I have third-party software that I call from my script and that
software has to be called with different environmental settings on RH 9 than it does
for RH 7.

Mark
 
T

Tore Aursand

$^O gives the O/S name, in my case : 'linux', but I want to run my Perl
script on RH 7.X and RH 9.x of Linux.

Why? And have in mind that Red Hat is just a Linux distribution; The OS
is Linux no matter what distribution (of Linux) you're running.
 
J

Joe Smith

Mark said:
Well, because I have third-party software that I call from my script and that
software has to be called with different environmental settings on RH 9 than it does
for RH 7.

Why? If it is because one distribution as files in a particular
directory and the other does not, then test for the existence of
that directory.

Testing the OS (the version of the kernel) won't help.
$os = `uname -r`;
if ($os =~ /^2.4.20-28.\d+$/) {
print "Kernel version indicates patched RH7.1 or patched RH9\n";
}

-Joe
 
J

James Willmore

[a private response was sent - which you neglected to note here]
[don't top post - it's rude]
[reformated message follows]

Mark J Fenbers said:
Well, because I have third-party software that I call from my script and that
software has to be called with different environmental settings on RH 9 than it does
for RH 7.

Keep your eye on the prize - the environment variables, not the OS.
If you code based upon the various distros of Linux, be prepared to
include some 50+ tests (one for each version of Red Hat, plus other
Linux distros). Red Hat is not the only distro out there (I use SuSE
and have tried others, including Red Hat).

My guess is you're looking for, maybe, a language setting? Or a
locale setting? If so, test for the settings, not the distro.

Just a side note - what happens when you get people like me who
*change* the environment settings for one reason or another. What
happens then? From your logic, if I use RH7, and the script sets up
"stuff" based upon the OS, your script *may* fail because I changed an
environment setting you're depending upon being set properly (because
it's that way for RH7 out of the box).

Give some thought to the above statements. Maybe this is all moot. I
just would *not* test based upon a Linux distro. Too many things can
go South real quick.

HTH

Jim
(jwillmore _at_ adelphia _dot_ net)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top