There is a shell script to do most of this in Kochan and Wood's book,
"UNIX Security."
Mark J. Hewitt
usenet: ...!{mcvax,uunet}!ukc!kernel!mjh
other: mjh%kernel.uucp at ukc.ac.uk
voice: (+44) 532 444566
fax: (+44) 532 420183
paper: Kernel Technology Ltd,
Development Centre, 46 The Calls,
Leeds, LS2 7EY, West Yorkshire, UK