summaryrefslogtreecommitdiff
path: root/tools/zlook
blob: 43b18b7799c7385b1a9c2ca95eefdfe72d42864a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/sh
#
# ZLOOK:  AUTHOR: "Jr" Spidell      DATE: April 25, 1992
#
# this script will only run properly by root
#       on a zephyr server node
# output: accounts logged into zephyr
#         nodes running a host manager

TEMPFILE=/usr/tmp/zephyr.$$
TEMPFILE2=/usr/tmp/zephyr2.$$
DBFILE=/usr/tmp/zephyr.db       # where zephyrd dumps its data after a kill -FPE

# the next "magic numbers" for the servers come from looking at server.list
# the '1' or '3' corresponds to the position of the server name in the file
# 'server.list'
# NOTE: these numbers will need to be changed if the server.list file gets
# changed.  (server.list resides in the directory /usr/athena/lib/zephyr)
CAP_SERVER="3:"
FRED_SERVER="1:"

# test for root
if test "`whoami`" != root
 then
   echo "you must be root to run this script"
   exit
fi

# test for no options
if test $# -eq 0
then USAGE="yes"
     echo "no options given."
     echo ""
fi

# test for server node
if test -z "`ps aux | grep zephyrd | grep -v grep | awk '{print $2}'`"
 then echo "you must be on a zephyr server (ie cap, fred)"
      exit
fi

# root doesn't have this in its path
path=$PATH
PATH=$path":/usr/local/bin:/bin:"

for argument in $*
do
 case $argument in
  -N)# extract the running host managers
    ZHM=yes
    ;;

  -s)# extract the suns (nodes that use fred as their server )
    FRED=yes
    ;;

  -d)# extract the decs (nodes that use cap as their server )
    CAP=yes
    ;;

  -A)# extract logged in users
     EXTRACT_USERS=yes
     ;;

  -O)# list options
     USAGE=yes
    ;;

  -e)# list exposure values
     EXPO=yes
     ;;

  -g)# list group name
      GRP=yes
     ;;

  -t)# list time user logged in to zephyr
      TME=yes
     ;;

  -n)# list user's node
      NOD=yes
     ;;
                                                            
  -ni)# list user's "world name" or "nickname" ie joe B. Blow
      NIK=yes
     ;;

  -G*)# list users by given group name
      # note -g option does not display along with -G option
      # (sort of redundant don't ya think?)

    if test "$argument" = "-G"
     then echo "you must specify a group for -G option"
          zlook -o
     exit
    fi
    /accts/caspidell/shelldir/zlook -A -g`echo " $* " | sed "s/-G/ /g"` | grep `echo $argument
 | sed "s/-G//"`  | sed "s/`echo $argument| sed "s/-G//g"`//"
  # | awk '{print $1}'
    exit;;

  -s)# subscription information
     # nothing here, yet...
     ;;

  -?)# unknown option
     USAGE="yes"
     echo "unknown option $argument"
     echo ""
    ;;

 esac # end of options
done # end of arguments


#############
# -O option #
#############
if test "$USAGE" = "yes"
then
    echo "zlook [-N] [-d] [-s] [-G<groupname>] [-A] [-t] [-ni] [-n] [-e] [-o]"
    echo ""
    echo "     -N  nodes currently running a zephyr host manager."
    echo "     -d  only decs currently running zhm"
    echo "     -s  only suns currently running zhm"
    echo "     -G<group> users by group name."
    echo "     -A  all users currently logged into zephyr."
    echo "     -g  give user's group association"
    echo "     -t  give time user logged into zephyr."
    echo "     -n  give user's node."
    echo "     -e  give user's exposure level."
    echo "     -ni give user's full name (ie Joe B. Blow)."
    echo "     -O  option descriptions. (this screen)"
    echo ""
    echo " options -t, -n, -e, -ni must be accompanied by -A or -G<group>"
    echo " options -d and -s must be accompanied by -N"
    echo ""
fi

#############
# -N option #
#############
if test "$ZHM" = "yes"
 then

    # this is for all nodes
    SERVER=":"

    # extract only nodes that use cap as their server
    if test "$CAP" = "yes"
    then
       SERVER=$CAP_SERVER
    fi

    # extract only nodes that use fred as their server
    if test "$FRED" = "yes"
    then
       SERVER=$FRED_SERVER
    fi

    # dump the database
    kill -FPE `ps aux | grep zephyrd | grep -v grep | awk '{print $2}'`

    # cross-reference the internet adresses with node names
    for address in `cat /usr/tmp/zephyr.db | grep 131.198 | grep $SERVER | grep -v rockwell |
grep -v SERV | sed "s/\/[0-9]://"`
    do
    ypcat hosts | grep "$address " | awk '{ print $2 }' | sed "s/.cca.cr.rockwell.com//" >> $T
EMPFILE
    done
    cat $TEMPFILE | sort
    rm $TEMPFILE
fi



#############
# -A option #
#############

if test "$EXTRACT_USERS" = "yes"
 then
# dump the database
  kill -FPE `ps aux | grep zephyrd | grep -v grep | awk '{print $2}'`

  for instance in `cat /usr/tmp/zephyr.db | grep @cca.cr.rockwell.com/ | sed "s/ /~/g"`
      do
#------------------
# display user name
#------------------
      PEOPLE=`echo $instance | awk '{FS="@"}{print $1}'`
      echo $instance | awk '{FS="@"}{printf("%-10s", $1)}' >> $TEMPFILE

#---------------------------------
# display group association
#---------------------------------
      if test "$GRP" = "yes"
       then
         GROUP=`ypcat passwd | grep $PEOPLE: | awk '{FS=":"}{print $4}'`
         ypcat group | grep ":$GROUP:" | awk '{FS=":"}{printf("%-9s", $1)}' >> $TEMPFILE
      fi

#--------------------
# display node
#--------------------
      if test "$NOD" = "yes"
       then
       echo $instance | sed "s/.cca.cr.rockwell.com//g" | awk '{FS="/"}{printf("%-8s ",$2)}' >
> $TEMPFILE
      fi

#-----------------------
# display exposure level
#-----------------------
      if test "$EXPO" = "yes"
       then
        echo $instance | awk '{FS="/"}{printf("%s ", $5)}' >> $TEMPFILE
      fi

#-------------
# display time
#-------------
      if test "$TME" = "yes"
       then
       echo $instance | sed "s/~/ /g" | sed "s/:[0-9][0-9] [0-9][0-9][0-9][0-9]//" | awk '{FS=
"/"}{printf("%-10s ",$3)}' >> $TEMPFILE
      fi

#-----------------
# display nickname
#-----------------
      if test "$NIK" = "yes"
       then
       ypcat passwd | grep $PEOPLE: | awk '{FS=":"}{printf("%s ", $5)}' >> $TEMPFILE
      fi
      echo "" >>$TEMPFILE
  done
  cat $TEMPFILE | sort
  rm $TEMPFILE
fi