Bilal Muddassir forced the electrons to say:
> 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}

May I offer a suggestion?

awk in itself is very powerful, and perform the functions of grep and wc on
its own. So a simpler version will be:

finger @$1 | awk -vnum=0 ' /./ { num++ } END { print num - 2 } '

(The -2 is for the two lines that appear at the beginning of finger o/p - one
 with the machine name and the other, a header line.)

This works even if somebody has a login ID as 'Login'.

Put the o/p of the above in a variable, and if it is < 0, finger failed
(connection refused). For other values, print out the string you want.

Binand

-- 
#include <stdio.h>                                   | Binand Raj S.
char *p = "#include <stdio.h>%cchar *p = %c%s%c;     | This is a self-
int main(){printf(p,10,34,p,34,10);return 0;}%c";    | printing program.
int main(){printf(p,10,34,p,34,10);return 0;}        | Try it!!
--------------------------------------------------------------------
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.

Reply via email to