[ale] Need AWK Guru input

Geoffrey Myers lists at serioustechnology.com
Mon Aug 1 15:49:35 EDT 2011


The Don Lachlan wrote:
> On Mon, Aug 01, 2011 at 06:46:30PM +0000, Lightner, Jeff wrote:
>> The man page on RHEL says lsb_release parses the /etc/<distrib>-release
>> file which is why I made my comments as that would be /etc/redhat-release
>> on RHEL.
> 
> My point was that 'lsb_release' is a standard used in multiple distributions
> and if RHEL decides to change the format of "/etc/redhat-release", they will
> update lsb_release to parse it and your script chugs along happily.
> 
> Compare:
> 
>   $ lsb_release -r | cut -d'.' -f1
> 
> with:
> 
>   $ awk '/release/ { for (x=1;x<=NF;x++) if ($x~"release") print $(x+1) }' /etc/redhat-release

These two scripts produce different output.

For example, if /etc/redhat-release contains:

Red Hat Enterprise Linux Server release 5.4 (Tikanga)

Your script produces:

Release:        5

Whereas, the second returns:

5.4

I'm pretty sure the OP didn't want the 'Release:' in the output.
I think the OP needs to be more specific as to what they want.

> 
> There's already a tool out there to tell you, sans major (or any) parsing,
> what your distribution's release is. That tool will be updated if the syntax
> of the underlying raw file is modified. OTOH, trying to parse redhat-release
> means you have to update your script if the syntax of the release file
> changes.
> 
> My overall point is, instead of asking, "How do I parse this file with AWK?"
> the better question is, "How do I easily obtain the major revision number of
> RHEL?" To which, lsb_release is the answer.
> 
> Is that clearer?
> 
> -L
> 
> 
> 
>> With /etc/redhat-release in place:
>> lsb_release -a
>> LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
>> Distributor ID: RedHatEnterpriseServer
>> Description:    Red Hat Enterprise Linux Server release 5.5 (Tikanga)
>> Release:        5.5
>> Codename:       Tikanga
>>
>> Without /etc/redhat-release in place:
>> # mv /etc/redhat-release /etc/redhat-release.20110801
>> # lsb_release -a
>> LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
>> Distributor ID: n/a
>> Description:    (none)
>> Release:        n/a
>> Codename:       n/a
>>
>> The info in /etc/lsb_release.d on RHEL doesn't contain the distro version but rather the LSB version and my read of the man page says that is the way it should be (except man page talks about a single /etc/lsb_release file - RedHat likes to expand such things into .d directories so you can have multiple things configured via separate files rather than all in one big file).
>>
>>
>> -----Original Message-----
>> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of The Don Lachlan
>> Sent: Monday, August 01, 2011 2:03 PM
>> To: ale at ale.org
>> Subject: Re: [ale] Need AWK Guru input
>>
>> On Mon, Aug 01, 2011 at 05:35:55PM +0000, Lightner, Jeff wrote:
>>> Cool - never ran across that lsb_release command before.
>>> However it gives Version.Subversion (e.g. 5.5, 5.3, 5.1) as well as the
>>> keyword "Release:" so if the user just wants the major version (5) he'd
>>> still need to strip the trailing number (if there - 5.0 just shows up as
>>> 5) and the keyword.   Still might be simpler to pipe that to awk since it
>>> gives less information though.
>>> One downside to either approach is it might not be correct - sometimes
>>> admins muck with /etc/redhat-release because applications check it to
>>> install and fail.   (Oracle apps are great for that - they tell you RHEL5
>>> is supported but their installation checks fail if they don't find it is
>>> RHEL4 for some things.)
>>> Often such hacks are only done on /etc/redhat-release and /etc/issue is
>>> left unmolested.   My read of lsb_release man page says it parses from
>>> /etc/redhat-release so using /etc/issue might be a better way to go.
>> The reason I asked about 'lsb_release -r' is because it's used on many
>> distributions and more standardized. If something changes in
>> /etc/redhat-release or whatever raw file, the distro maintains lsb_release
>> and your script chugs along happily.
>>
>> -L
>>
>>> -----Original Message-----
>>> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of The Don Lachlan
>>> Sent: Monday, August 01, 2011 11:29 AM
>>> To: ale at ale.org
>>> Subject: Re: [ale] Need AWK Guru input
>>>
>>> On Mon, Aug 01, 2011 at 11:17:33AM -0400, Dennis Ruzeski wrote:
>>>> Something like this?
>>>> cat /etc/redhat-release |awk  '/release/ { for (x=1;x<=NF;x++) if
>>>> ($x~"release") print $(x+1) }'
>>> Wouldn't 'lsb_release -r' hand back the same info?
>>>
>>> -L
>>>
>>>> On Mon, Aug 1, 2011 at 10:52 AM, Chuck Payne <terrorpup at gmail.com> wrote:
>>>>> Guys,
>>>>>
>>>>> I am working on adding servers to my Satellite server, and I like to
>>>>> be able to get in with a script and call on the following
>>>>>
>>>>> /etc/redhat_release
>>>>>
>>>>> But I only want to get the number, so that I can see if it RHEL 4 or
>>>>> 5, I been trying to do with awk, but I am not able to get anything,
>>>>> what is the best way to only put numbers?
>>>>>
>>>>> --
>>>>> (678) 636-9678
>>>>> -----------------------------------------
>>>>> Discover it! Enjoy it! Share it! openSUSE Linux.
>>>>> -----------------------------------------
>>>>> openSUSE -- en.opensuse.org/User:Terrorpup
>>>>> openSUSE Ambassador/openSUSE Member
>>>>> skype,twiiter,identica,friendfeed -- terrorpup
>>>>> freenode(irc) --terrorpup/lupinstein
>>>>> Register Linux Userid: 155363
>>>>>
>>>>> Have you tried SUSE Studio? Need to create a Live CD,  an app you want
>>>>> to package and distribute , or create your own linux distro. Give SUSE
>>>>> Studio a try. www.susestudio.com.
>>>>>
>>>>> _______________________________________________
>>>>> Ale mailing list
>>>>> Ale at ale.org
>>>>> http://mail.ale.org/mailman/listinfo/ale
>>>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>>>> http://mail.ale.org/mailman/listinfo
>>>>>
>>>> _______________________________________________
>>>> Ale mailing list
>>>> Ale at ale.org
>>>> http://mail.ale.org/mailman/listinfo/ale
>>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>>> http://mail.ale.org/mailman/listinfo
>>> _______________________________________________
>>> Ale mailing list
>>> Ale at ale.org
>>> http://mail.ale.org/mailman/listinfo/ale
>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>> http://mail.ale.org/mailman/listinfo
>>>
>>>
>>>
>>> Proud partner. Susan G. Komen for the Cure.
>>>
>>>
>>> Please consider our environment before printing this e-mail or attachments.
>>>
>>> ----------------------------------
>>> CONFIDENTIALITY NOTICE: This e-mail may contain privileged or confidential information and is for the sole use of the intended recipient(s). If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.
>>> ----------------------------------
>>>
>>> _______________________________________________
>>> Ale mailing list
>>> Ale at ale.org
>>> http://mail.ale.org/mailman/listinfo/ale
>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>> http://mail.ale.org/mailman/listinfo
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo


-- 
Until later, Geoffrey

"I predict future happiness for America if they can prevent
the government from wasting the labors of the people under
the pretense of taking care of them."
- Thomas Jefferson


More information about the Ale mailing list