#!/bin/sh
DELDIR="/root/crontab_test/test"
#3 minute ago
DELTIME="-mmin +3"
#delete file type
FILETYPE1="‘*.txt‘"
FILETYPE2="‘*.log‘"
#write to tmp file
rm crontab_del_3min -f
touch crontab_del_3min
# every minute delete *.txt file 3 minutes ago
echo \* \* \* \* \* find $DELDIR $DELTIME -name $FILETYPE1 -exec rm -f {} \\\; >> crontab_del_3min
# every minute delete *.log file 3 minutes ago
echo \* \* \* \* \* find $DELDIR $DELTIME -name $FILETYPE2 -exec rm -f {} \\\; >> crontab_del_3min
#write to crontab
crontab crontab_del_3min
#start to crontab
/etc/init.d/crond restart