OS Version

Discussion in 'Perl Misc' started by Mark J Fenbers, Mar 1, 2004.

  1. $^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
    Mark J Fenbers, Mar 1, 2004
    #1
    1. Advertising

  2. Mark J Fenbers

    Ben Morrow Guest

    Mark J Fenbers <> wrote:
    >
    > $^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

    --
    don't get my sympathy hanging out the 15th floor. you've changed the locks 3
    times, he still comes reeling though the door, and soon he'll get to you, teach
    you how to get to purest hell. you do it to yourself and that's what really
    hurts is you do it to yourself just you, you and noone else **
    Ben Morrow, Mar 1, 2004
    #2
    1. Advertising

  3. Mark J Fenbers wrote:
    >
    > $^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
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    Josef Möllers, Mar 1, 2004
    #3
  4. Mark J Fenbers wrote:
    > $^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ürgen Exner, Mar 1, 2004
    #4
  5. On Mon, 01 Mar 2004 10:04:30 -0500, Mark J Fenbers wrote:

    > $^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?
    James Willmore, Mar 1, 2004
    #5
  6. 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

    James Willmore wrote:

    > On Mon, 01 Mar 2004 10:04:30 -0500, Mark J Fenbers wrote:
    >
    > > $^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?
    Mark J Fenbers, Mar 1, 2004
    #6
  7. Mark J Fenbers

    Tore Aursand Guest

    On Mon, 01 Mar 2004 10:04:30 -0500, Mark J Fenbers wrote:
    > $^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.


    --
    Tore Aursand <>
    "First, God created idiots. That was just for practice. Then He created
    school boards." -- Mark Twain
    Tore Aursand, Mar 1, 2004
    #7
  8. Mark J Fenbers

    Joe Smith Guest

    Mark J Fenbers wrote:

    > 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
    Joe Smith, Mar 1, 2004
    #8
  9. [a private response was sent - which you neglected to note here]
    [don't top post - it's rude]
    [reformated message follows]

    Mark J Fenbers <> wrote in message news:<>...
    > James Willmore wrote:
    >
    > > On Mon, 01 Mar 2004 10:04:30 -0500, Mark J Fenbers wrote:
    > >
    > > > $^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 :)



    > 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)
    James Willmore, Mar 1, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Sheen

    Express Version Kills Current Version

    Lloyd Sheen, Jun 29, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    548
    Ken Cox [Microsoft MVP]
    Jul 2, 2004
  2. Ily
    Replies:
    2
    Views:
    416
    Eliyahu Goldin
    Jul 27, 2005
  3. V Green
    Replies:
    0
    Views:
    824
    V Green
    Feb 5, 2008
  4. PA Bear [MS MVP]
    Replies:
    0
    Views:
    929
    PA Bear [MS MVP]
    Feb 5, 2008
  5. MowGreen [MVP]
    Replies:
    5
    Views:
    1,993
    PA Bear [MS MVP]
    Feb 9, 2008
Loading...

Share This Page