PDA

View Full Version : Removing files generated 2 days back.


sharath_menon
08-02-02, 07:53
I am generating dmp file everyday through crontab. The file generated is filename010802.dmp. There are a number of files that are generated. I delete the previous days files manually. Is there anyway i can delete it using a script so that i can schedule it in the crontab.

If for e.g today the file generated will be filename010802.dmp
Before it starts generating the file filename310702 should be deleted.
Same way when the file is created tomorow, today's file filename010802.dmp should be deleted and then the creating of file filename020802.dmp should happen.

Please help

Thanks and Regards
Sharath

vaayu.a
08-03-02, 08:16
hi
try this

for file in `ls | grep '.tmp$'`
do
fdate=`echo $file | cut -c5-6`
cdate=`date +%D | cut -c4-5`
diff=`expr $cdate - $fdate`
if[ $diff -eq 1 ] ; then
rm $file
# here you insert the code which genarates the file
fi
done

here i'm assuming your files are in the form of
file010802.tmp
file020802.tmp
make necessary changes and put it in crontab

bye

kbadeau
08-27-02, 12:28
try find with -mtime, -ctime, or -atime

for example:
find /location -ctime +1 -exec rm {} \;

This should remove any file that was created more than 1 day ago. Be careful though in that it seems that +1 is not necessarily 24 hours from the current time but more like before the start of the previous day.

I haven't sat down to really figure that out, all I know is that specifying one day usually leaves me at least 2 days.