1832351 Members
2392 Online
110041 Solutions
New Discussion

Script

 
SOLVED
Go to solution
Sundar_7
Honored Contributor

Script

Hi All,

I just in need of U Guys help for a Script..

The thing I am trying is

* using /usr/include/sys/errno.h

I am trying to write a script which will accept error number as the input

and will give the detail on that error..

From errno.h I managed to extract the one line report for the given error number..

But then I need one more thing..

It should take the detailed description for that error from the man page of errno

and give me the description from that man page..


Example :

Suppose if I give number 227 for the script..

It should take the following line from /usr/include/sys/errno.h

and should extract ONLY THE DEFINITION of EADDRNOTAVAIL from man page..

Please give me a awk/sed script for doing this..

/usr/include/sys/errno.h
=========================

# define EADDRNOTAVAIL 227 /* Can't assign requested address */


Man page extract of ERRNO..
===========================

[EADDRNOTAVAIL]
Cannot assign requested address. Normally results from
an attempt to create a socket with an address not on
this machine.

[EAFNOSUPPORT] Address family not supported by protocol family. An
address incompatible with the requested protocol was
used. For example, you should not necessarily expect
to be able to use PUP Internet addresses with ARPA
Internet protocols.



Thanks for Ur time and the Help

Sundar
Learn What to do ,How to do and more importantly When to do ?
5 REPLIES 5
Robin Wakefield
Honored Contributor
Solution

Re: Script

man errno | sed -n '/.*NOTAVAIL.*/,/^$/p'

as an example, would be a good start.

Robin.
Sundar_7
Honored Contributor

Re: Script

Thanks so much..

U really deserve 20 but then only 10 possible

Bye

Sundar
Learn What to do ,How to do and more importantly When to do ?
Alan Riggs
Honored Contributor

Re: Script

read NUM
STRING=$(awk -v NUM=$NUM '$4==NUM {print $3}' /usr/include/sys/errno.h)
man errno | eval sed -n '/.*${STRING}.*/,/^$/p'
Sundar_7
Honored Contributor

Re: Script

Hi,

Thanks to both..

But sorry I have to take Ur time once more.

Can U please explain how sed part really

cuts only that string from the file.

Sorry I am really new to Scripting..

Please help me out by explaining what it does..

Thanks

If possible U can leave Ur message at

SundarHp@Hotmail.com

Bye and waiting

Sundar


Learn What to do ,How to do and more importantly When to do ?
Robin Wakefield
Honored Contributor

Re: Script

Basically, the comma-separated slashes define the start and end address.
sed looks for a match on the 1st address, and stops looking when it matches on the 2nd address.
The -n says "don't print anything", the p says "output only what matches". These two switched are invariably used together.

Robin