-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlwho
89 lines (76 loc) · 1.96 KB
/
lwho
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
#!/bin/sh
#
# Copyright (c) 2001-2015 Matthew Pearson <[email protected]>.
#
# These scripts are free. There is no warranty; your mileage may vary.
# Visit http://creativecommons.org/licenses/by-nc-sa/4.0/ for more details.
#
# $Id$
# print a list of other users on the system
#
PATH=/bin:/usr/bin
USAGE="usage: `basename $0` [-cqsh]"
VSAGE="\t-c don't check console logins\n\
\t-q print nothing if no-one else is using host\n\
\t-s print abbreviated output (less info on root logins)\n\
\t-h print this message\n"
# on some systems there is no nawk
awk 1 /dev/null >/dev/null 2>&1
[ $? -eq 0 ] && alias nawk=awk
while getopts cqsh arg
do
case $arg in
c) noconsole=y ;;
q) quiet=y ;;
s) short=y ;;
h) echo $USAGE
printf "$VSAGE"
exit 0 ;;
*) echo $USAGE
exit 1 ;;
esac
done
# get a list of users other than yourself
#wholines=`who --lookup 2>/dev/null`
#[ $? -eq 0 ] || wholines=`who`
wholines=`who`
wholist=`echo "$wholines" | sort | fgrep -v __G_USER__`
# optionally strike out console users
[ "$noconsole" ] && wholist=`echo "$wholist" | grep -v console`
users=`echo "$wholist" | cut -d" " -f1 | uniq`
if [ "$short" ]
then
usercnt=`echo "$users" | wc -l`
# simple list of users, including root
if [ "$usercnt" -ge 2 ]
then
echo $usercnt " users:" $users
elif [ "$users" ]
then
echo "1 user:" $users
fi
else
# strike out root users
users=`echo "$users" | grep -v root`
usercnt=`echo "$users" | wc -l`
# all users but root on one line
if [ "$usercnt" -ge 2 ]
then
echo $usercnt " users:" $users
elif [ "$users" ]
then
echo "1 user:" $users
fi
# and root users along with the connecting host
roots=`echo "$wholist" | nawk '/root/ {
sub(":.*","",$6)
if ($6)
print $6 # connecting from
else
print $2 # or connected to
}' | sed -e 's/)//' -e 's/(//' | uniq`
[ "$roots" ] && echo "root via:" $roots
fi
[ "${users}${roots}${quiet}" ] || \
echo "no one else on `uname -n`"
#EOF __TAGGED__