#!/bin/bash
#
# cleanup-kdumps - Only keep the latest two kdumps
#
set -e

ENABLED=0
KDUMP_ENABLED="/etc/default/bonding-kdump-enabled"
test -f $KDUMP_ENABLED && . $KDUMP_ENABLED
test "$ENABLED" != "0" || exit 0

if [ -d "/var/crash" ] ; then
    find /var/crash/ -mindepth 1 -maxdepth 1 -type d | sort | head -n -2 | xargs --no-run-if-empty rm -i -rf | logger -i -t 'cron'
fi
