#!/bin/sh
#
#
# clean_core. This script was split off cron.daily
# Please add your local changes to cron.daily.local
# since this file will be overwritten, when updating your system.
#
# Copyright (c) 2003 SuSE Linux AG, Nuernberg, Germany.
#
# Please submit bugfixes or comments via http://www.suse.de/feedback/
#
# Author: Burchard Steinbild <bs@suse.de>, 1996
#         Florian La Roche <florian@suse.de>, 1996
#
#
#


#
# paranoia settings
#
umask 022

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

#
# get configuration
#
if [ -f /etc/sysconfig/locate ] ; then
    . /etc/sysconfig/locate
fi
if [ -f /etc/sysconfig/cron ] ; then
    . /etc/sysconfig/cron
fi

#
# look for old core files and tell user about it.
#
if [ -z "$MAX_DAYS_FOR_CORE" ] ; then
    MAX_DAYS_FOR_CORE=5
fi

if [ -n "$RUN_UPDATEDB" -a "$RUN_UPDATEDB" = "yes" -a \
     -x /usr/bin/updatedb ] ; then
  for DUMMY in `find /var/lib/locatedb -mtime -7 2> /dev/null` ; do
    for COREFILE in `locate '*/core' '*/core.[0-9]*' 2> /dev/null` ; do
      for i in `find "$COREFILE" ! \( -fstype nfs -o -fstype NFS \) \
        \( -name core -o -name "core.[0-9]*" \) -type f \
        -mtime +"$MAX_DAYS_FOR_CORE" 2> /dev/null` ; do
        if [ -n "$DELETE_OLD_CORE" -a "$DELETE_OLD_CORE" = "yes" ] ; then
            echo "Deleting core file older than $MAX_DAYS_FOR_CORE days: $i"
            if test -x /usr/bin/file ; then
                echo file "$i"
                /usr/bin/file "$i"
            fi
            rm -f "$i"
        else
            echo "Found core file older than $MAX_DAYS_FOR_CORE days: $i"
            if test -x /usr/bin/file ; then
                echo file "$i"
                /usr/bin/file "$i"
            fi
        fi
      done
    done
  done
fi

exit 0
