head	1.12;
access;
symbols;
locks
	ids:1.12; strict;
comment	@# @;


1.12
date	2008.08.29.21.45.43;	author ids;	state Exp;
branches;
next	1.11;

1.11
date	2007.10.01.18.00.05;	author ids;	state Exp;
branches;
next	1.10;

1.10
date	2007.03.15.21.37.58;	author ids;	state Exp;
branches;
next	1.9;

1.9
date	2003.10.30.16.14.28;	author ids;	state Exp;
branches;
next	1.8;

1.8
date	2000.07.30.20.50.25;	author ids;	state Exp;
branches;
next	1.7;

1.7
date	2000.07.30.20.05.10;	author ids;	state Exp;
branches;
next	1.6;

1.6
date	2000.07.30.19.49.24;	author ids;	state Exp;
branches;
next	1.5;

1.5
date	98.09.28.21.33.12;	author ids;	state Exp;
branches;
next	1.4;

1.4
date	97.10.18.16.46.12;	author ids;	state Exp;
branches;
next	1.3;

1.3
date	97.10.10.18.44.13;	author ids;	state Exp;
branches;
next	1.2;

1.2
date	96.04.23.11.02.18;	author ids;	state Exp;
branches;
next	1.1;

1.1
date	96.04.22.21.14.24;	author ids;	state Exp;
branches;
next	;


desc
@@


1.12
log
@new time-style specification for "ls", achieving the traditional "Sep  6" format
 on the new DoC version of Ubuntu.
@
text
@#!/bin/sh -
#
#	lscan: scan of (estimated!) "active" accounts, shown in reverse
#	order of (estimated!) last login time, and fingerized for clarity.
#
#	usage: lscan <group>0+
#	If no groups are given all active accounts are considered.
#	*****Use sparingly***** in that form of usage,
#	as it does then rather strain the fileservers!
#
#	NOTE 1: now that e-mail delivery on most accounts creates and destroys
#	a lock-file in the home directory, the times are not really as useful
#	as they once were.
#
#	NOTE 2: the particular keywords and output parsings are probably
#	hopelessly specific to DoC. The requested fields are respectively
#	the username, the group, and the timestamp.
#
progname=`basename $0`
ls_time_style="+%b %e  %Y
%b %e %H:%M"


#
#	construct a suitable matching pattern for the groups
#
if [ $# -eq 0 ]; then	#pattern that matches all groups
	echo "(warning: scanning for all active accounts; may take some time.....)" >&2
	groups_match='/homes/'
else
	gids=""
	for group in $* ; do
		gid=`grep "^$group:" /etc/group | sed -e "s/^$group:[^:]*://" -e 's/:.*$//'`
		if [ `echo $gid | grep -c '^[0-9][0-9]*$'` -ne 1 ]; then
			echo "($group not a recognized group, ignoring)" >&2
		elif [ -z "$gids" ]; then
			gids="$gid"
		else
			gids="$gids|$gid"
		fi
	done

	if [ -z "$gids" ]; then
		echo "$progname: no recognized groups!" >&2
		exit 1
	fi

	groups_match="^[^:]*:[^:]*:[^:]*:($gids):.*/homes/"
fi


#
#	try to find active accounts in the given groups
#
dirs=`egrep "$groups_match" /etc/passwd | sed -e '/disabled-.*sh/d' -e '/\/true/d' -e '/\/false/d' -e '/[: ][aA]ccount[: ]/d' -e '/[: ][mM]aintenance[: ]/d' -e '/[: ][aA]dministration[: ]/d' -e '/[: ][sS]ystem[: ]/d' -e '/[: ][tT]est[: ]/d' -e '/[: ][aA]cct[: ]/d' -e '/[: ][nN]umber[: ]/d' -e '/::/d' -e 's/:.*$//' -e 's|^|/homes/|'`
if [ -z "$dirs" ]; then
	echo "$progname: no active accounts in the given group(s)!" >&2
	exit 1
fi


#
#	OK, now do the big scan!
#
ls --time-style="$ls_time_style" -laFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | sed -e 's/^[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*\).*$/\1	\2	\3/' | fingerize
@


1.11
log
@added time-style specification for "ls".
@
text
@d20 2
d65 1
a65 1
ls --time-style=locale -laFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | sed -e 's/^[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*\).*$/\1	\2	\3/' | fingerize
@


1.10
log
@more robust parsing of final output.
@
text
@d63 1
a63 1
ls -laFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | sed -e 's/^[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*\([^ 	][^ 	]*\)[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*\([^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*[ 	][ 	]*[^ 	][^ 	]*\).*$/\1	\2	\3/' | fingerize
@


1.9
log
@removed the -g option from usages of ls: previously this meant
 "show group *as well as* owner" - or on SuSE it was just ignored, since
 -l there already meant that - but on Mandrake it means
 "show group *but not* owner", which is horrible!
@
text
@d15 3
a17 3
#	NOTE 2: the particular keywords and colrm numbers are probably
#	hopelessly specific to DoC. The removed columns are respectively
#	the permissions and link count, the size, and the directory name.
d63 1
a63 1
ls -laFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | colrm 1 15 | colrm 20 27 | colrm 34 | fingerize
@


1.8
log
@more patterns indicating disabled or defunct accounts.
@
text
@d63 1
a63 1
ls -lgaFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | colrm 1 15 | colrm 20 27 | colrm 34 | fingerize
@


1.7
log
@further colrm argument tweaking - maybe RedHat 5 -> RedHat 6 broke it?
@
text
@d53 1
a53 1
dirs=`egrep "$groups_match" /etc/passwd | sed -e '/disabled-.*sh/d' -e '/[: ][aA]ccount[: ]/d' -e '/[: ][mM]aintenance[: ]/d' -e '/[: ][aA]dministration[: ]/d' -e '/[: ][sS]ystem[: ]/d' -e '/[: ][tT]est[: ]/d' -e '/[: ][aA]cct[: ]/d' -e '/[: ][nN]umber[: ]/d' -e '/::/d' -e 's/:.*$//' -e 's|^|/homes/|'`
@


1.6
log
@we're back to /etc/passwd and /etc/group as our form of passwd and group
 databases respectively.
@
text
@d63 1
a63 1
ls -lgaFLdt $dirs 2>&1 | egrep -v 'visitors| -> | not found|Permission denied|No such file or directory' | colrm 1 14 | colrm 20 27 | colrm 34 | fingerize
@


1.5
log
@we now access the passwd and group databases using "ypcat" rather than
 via local files
there now seem to be more error cases to parse away in the final output,
 and the arguments to ls and colrm needed tweaking a bit for Linux.
@
text
@d31 1
a31 1
		gid=`ypcat group | grep "^$group:" | sed -e "s/^$group:[^:]*://" -e 's/:.*$//'`
d53 1
a53 1
dirs=`ypcat passwd | egrep "$groups_match" | sed -e '/disabled-.*sh/d' -e '/[: ][aA]ccount[: ]/d' -e '/[: ][mM]aintenance[: ]/d' -e '/[: ][aA]dministration[: ]/d' -e '/[: ][sS]ystem[: ]/d' -e '/[: ][tT]est[: ]/d' -e '/[: ][aA]cct[: ]/d' -e '/[: ][nN]umber[: ]/d' -e '/::/d' -e 's/:.*$//' -e 's|^|/homes/|'`
@


1.4
log
@changed to only eliminate disabled shells, rather than the cases
 "disabled machine" or "disabled homedir".
(Of course, this still unfortunately eliminates people who've been
 temporarily suspended or whatever, and also it's likely the case
 "disabled homedir" will be eliminated further down by the filtering of
 the output of ls. But at least these cases are rarer.)
@
text
@d31 1
a31 1
		gid=`grep "^$group:" /etc/group | sed -e "s/^$group:[^:]*://" -e 's/:.*$//'`
d53 1
a53 1
dirs=`egrep "$groups_match" /etc/passwd | sed -e '/disabled-.*sh/d' -e '/[: ][aA]ccount[: ]/d' -e '/[: ][mM]aintenance[: ]/d' -e '/[: ][aA]dministration[: ]/d' -e '/[: ][sS]ystem[: ]/d' -e '/[: ][tT]est[: ]/d' -e '/[: ][aA]cct[: ]/d' -e '/[: ][nN]umber[: ]/d' -e '/::/d' -e 's/:.*$//' -e 's|^|/homes/|'`
d63 1
a63 1
ls -lgaFLdc $dirs 2>&1 | egrep -v 'visitors| -> | not found' | colrm 1 13 | colrm 20 27 | colrm 34 | fingerize
@


1.3
log
@explained the times are not as useful as they once were,
 because of the new e-mail delivery protocol (involving a home directory
 lock-file).
@
text
@d53 1
a53 1
dirs=`egrep "$groups_match" /etc/passwd | sed -e '/disabled-/d' -e '/[: ][aA]ccount[: ]/d' -e '/[: ][mM]aintenance[: ]/d' -e '/[: ][aA]dministration[: ]/d' -e '/[: ][sS]ystem[: ]/d' -e '/[: ][tT]est[: ]/d' -e '/[: ][aA]cct[: ]/d' -e '/[: ][nN]umber[: ]/d' -e '/::/d' -e 's/:.*$//' -e 's|^|/homes/|'`
@


1.2
log
@variable name and comment clarity improvements.
@
text
@d11 5
a15 1
#	NOTE: the particular keywords and colrm numbers are probably
@


1.1
log
@Initial revision
@
text
@d4 1
a4 1
#	order of (estimated!) login-time, and fingerized for clarity.
d25 1
a25 1
	groups=""
d30 2
a31 2
		elif [ -z "$groups" ]; then
			groups="$gid"
d33 1
a33 1
			groups="$groups|$gid"
d37 1
a37 1
	if [ -z "$groups" ]; then
d42 1
a42 1
	groups_match="^[^:]*:[^:]*:[^:]*:($groups):.*/homes/"
@
