Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Location
    India
    Posts
    1

    Unanswered: 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

  2. #2
    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

  3. #3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •