Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / whoison
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         whoison
5 # RCS:          $Header: whoison,v 1.1 97/05/20 19:56:29 defaria Exp $
6 # Description:  A script to show you who is on the system
7 # Author:       Andrew DeFaria, California Language Labs
8 # Created:      Wed May 14 00:40:02 PDT 1997
9 # Modified:
10 # Language:     Korn Shell
11 #
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 tmpprefix=/tmp/whoison
16 command="who | cut -f1 -d' ' | sort -u"
17
18 function cleanup {
19   if [ ! -z $"tmpprefix" ]; then
20     rm -f ${tmpprefix}*
21   fi
22
23   exit
24 } # cleanup
25
26 trap cleanup INT EXIT
27
28 if [ -z "$PAGER" ]; then
29   pager=more
30 else
31   pager="$PAGER"
32 fi
33
34 function report_whoison {
35   machine="$1"
36
37   if [ "$machine" = "$(uname -n)" ]; then
38     eval $command > $tmpprefix.$$
39   else
40     remsh $machine -n "$command" > $tmpprefix.$$
41   fi
42
43   declare -i nbr_of_users=$(wc -l $tmpprefix.$$ | tr -s " " | cut -f1 -d' ')
44
45   if [ $nbr_of_users -eq 1 ]; then
46     print "$nbr_of_users user on $machine:\n"
47   else
48     print "$nbr_of_users users on $machine:\n"
49   fi
50
51   declare -i i=1
52
53   cat $tmpprefix.$$ | while read user; do
54     print "$i: $user"
55     let i=i+1
56   done
57
58   print
59
60   rm -f $tmpprefix.$$
61 } # report_whoison
62
63 if [ $# -eq 0 ]; then
64   report_whoison "$(uname -n)" | $pager
65 else
66   for machine in "$@"; do
67     report_whoison "$machine"
68   done | $pager
69 fi
70
71 who | cut -f1 -d' ' | sort -u > $tmpprefix.$$
72