[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [LI] awk and checking of error codes



On Wed, Dec 01, 1999 at 03:49:14AM +0500, Bilal Muddassir wrote:
> bilal:/home/bilal $ cat ./test
> #!/bin/sh
> echo `date` `finger @$1|grep -v $1|grep -v Login|wc -l` $1 \
>         | awk '{print $8" ---------- " $7" user(s) present on "$2" "$3" at
> "$4}
> When the hostname is not valid etc, it would type Connection Refused and
> would print 0 users present --------
> I was wondering if I can check error returned before printing out with awk.
> I mean if it is possible.

You can do

x=`finger...`
if [ $? -eq 0 ]; then
	// successful
else
	// There was an error
fi;

But I just checked that finger doesn't set the exit status properly on
error. So you'll have to check for known error strings.

if [ $x = 'Connection refused' ]; then ...

	-Arun

--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.