SHA256
1
0
forked from pool/findutils
findutils/cron.daily.clean_core

82 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/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) 2006 SuSE Linux Products GmbH, Nuernberg, Germany.
#
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
# 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
IFS=$'\n'
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 -regex ".*/core\\.[0-9]+" \) -type f \
-mtime +"$MAX_DAYS_FOR_CORE" 2>/dev/null); do
if [ -x /usr/bin/file ]; then
type=$(/usr/bin/file "$i")
case $type in
*core\ file*)
;;
*)
continue
;;
esac
fi
if [ "$DELETE_OLD_CORE" = yes ]; then
echo "Deleting core file older than $MAX_DAYS_FOR_CORE days: $i"
if [ -x /usr/bin/file ]; then
echo file "$i"
echo "$type"
fi
rm -f "$i"
else
echo "Found core file older than $MAX_DAYS_FOR_CORE days: $i"
if [ -x /usr/bin/file ]; then
echo file "$i"
echo "$type"
fi
fi
done
done
done
fi
exit 0