If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Removing files generated 2 days back.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-02-02, 06:53
sharath_menon sharath_menon is offline
Registered User
 
Join Date: Aug 2002
Location: India
Posts: 1
Removing files generated 2 days back.

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
Reply With Quote
  #2 (permalink)  
Old 08-03-02, 07:16
vaayu.a vaayu.a is offline
Registered User
 
Join Date: Aug 2002
Location: india
Posts: 1
it should work

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
Reply With Quote
  #3 (permalink)  
Old 08-27-02, 11:28
kbadeau kbadeau is offline
Registered User
 
Join Date: Aug 2002
Posts: 2
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On