#!/bin/bash
rubbish=0
thedate=$(echo $(date))
dmk=$(echo $thedate | cut -d" " -f1-3,6)
tiome=$(echo $thedate | cut -d" " -f4-5)
mydate=$(echo $dmk", "$tiome":")
for t in *;
do
	if [[ "$t" == *exe.stackdump* ]];
	then
		echo "    ">>~/stackdump.log
		
		j=$[rubbish+1]
		echo "$mydate">>~/stackdump.log
		k=$(stat -c %y "$t")
		l=$(stat -c %s "$t")
		m=$(echo ${k:0:19})
		v=$(readlink -f "$t")
		w=$(dirname "$v")
		echo "Found $t -- logging modified date and removing."
		echo -e  "($l bytes) $t  -- removed from $w">>~/stackdump.log
		rm $t
		rubbish=$[rubbish+1]
	fi
done
if [[ "$rubbish" -gt "0" ]]; then
	echo -e "Logged and removed $rubbish STACKDUMP files this run."
else
	echo -e "No stackdump files found."
fi
		