3 # Find users whose last login is greater or less than the specified arguments.
4 # Needs the userinfo utility from http://userinfo.sourceforge.net/.
6 # Copyright (c) 2003-2004 Ben Kibbey <bjk@arbornet.org>
7 # Distributed under the terms of the General Public License version 2 or later.
9 # $Log: lastusers.sh,v $
10 # Revision 2.0 2004-12-05 19:44:23 bjk
13 # Revision 1.6 2004/11/21 18:48:07 bjk
14 # Updated to work with userinfo 2.0 (included in the archive).
16 # Revision 1.5 2004/05/01 19:10:37 bjk
17 # Changed option -b to -l.
19 # Displaying users who have never logged in is off by default. Specify with -n.
21 # Revision 1.4 2003/03/01 19:30:44 bjk
22 # Changed option -a to -b to specify logins before the arguments.
24 # Added options -s, -m, -r to specify seconds, minutes and hours.
26 # Revision 1.3 2003/03/01 16:14:46 bjk
27 # Added option -a to specify logins after the arguments.
29 # Revision 1.2 2003/02/26 17:43:22 bjk
30 # Dont run userinfo on matches. Dump only the username.
32 # Added option -n to suppress users who have never logged in.
34 # Revision 1.1 2003/02/22 20:57:18 bjk
44 CMD
="awk -F: '{print \$1}' < /etc/passwd | ui -O passwd.so -l -- -O login.so -lt --";
48 Find users whose last login is greater or less than the specified arguments.
49 Usage: $PN [-hnl] [-s seconds] [-m minutes] [-r hours] [-d days]
51 -s Logins seconds old.
52 -m Logins minutes old.
57 -l List users whose last login is at least as old as the arguments.
58 -n Also show users who have never logged in.
64 while getopts "d:w:hr:m:nls:y:" opt
; do
68 s
) tmp
=`expr $OPTARG`;;
69 d
) tmp
=`expr $OPTARG \* $DAY`;;
70 w
) tmp
=`expr $OPTARG \* $WEEK`;;
71 r
) tmp
=`expr $OPTARG \* $HOUR`;;
72 m
) tmp
=`expr $OPTARG \* $MINUTE`;;
73 y
) tmp
=`expr $OPTARG \* $YEAR`;;
80 WHEN
=`expr $WHEN + $tmp`;
90 shift $
(($OPTIND - 1));
95 eval $CMD |
while read line
; do
101 if [ x
"$sec" = x-
-o x
"$sec" = x\
! ]; then
102 if [ $NOLOGIN ]; then
110 if [ `expr $NOW - $sec` -gt $WHEN ]; then
114 if [ `expr $NOW - $sec` -lt $WHEN ]; then