#! /bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#ident	"$Header: rmjunk 1.4 89/10/11 $@(#)sadmin:shell/rmjunk	1.3"
#	remove files of dubious worth
#	Removes all files that match the patterns listed in the filelist file
#	starting at <starting-directory> (default /)
#	that are more than <days> old (default 4).

#!	chmod +x ${file}

if [ $# -lt 1 ]
then
	echo >&2 "Usage:  $0 filelist [ starting-directory ] [ days ]"
	exit 1
fi

#	generate list of -name arguments for find
if [ ! -r $1 ]
then
	echo >&2 "$0:  cannot read file '$1'"
	exit 1
fi
names=`sed -n '	/^#/d
		s/[ 	]\{1,\}#.*//
		/^[ 	]*$/d
	 '"	/./ s/.*/-o -name '&'/p
	 "  $1  |
	sed '1s/-o //'`
if [ -z "${names}" ]
then
	echo >&2 "$0:  no file names!"
	exit 1
fi

eval find ${2:-/} -type f -atime +${3:-4} '\(' ${names} '\)' \
	-print -exec rm {} '\;'
