Operating System - HP-UX
1843975 Members
1824 Online
110226 Solutions
New Discussion

Re: writing a script not going well

 
Dottie Hamilton
Contributor

writing a script not going well

I haven't written a script of this type in a very but I need to write one that will delete files from a directory that are more than 3 days old.
The format is filename.yymmdd and I am having problems getting it to pick up the date in this format and compare it to the file name.

Any help out there?

thanks
-DH
5 REPLIES 5
someone_4
Honored Contributor

Re: writing a script not going well

Hello Dottie ..
I have attached a script that you can modify to fit your needs the format is very easy you can make it clear out or delete any files or logs and it will always keep the date stamp of the file and even compress them.

I got it from the following ftp site.

ftp://contrib:9unsupp8@hprc.external.hp.com/sysadmin/

Hope this helps

~ Richard
Sajid_1
Honored Contributor

Re: writing a script not going well

hello,

If you just want to delete files which are 3 days old, use the find command:
# cd dir_path
# find . -xdev -type f -mtime +3 -exec rm {} \;

hth,
learn unix ..
Jean-Luc Oudart
Honored Contributor

Re: writing a script not going well

I answer a simlar request a while ago,
check the following thread.

Rgds,
Jean-Luc

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc8294b3ef09fd611abdb0090277a778c,00.html
fiat lux
A. Clay Stephenson
Acclaimed Contributor

Re: writing a script not going well

Hi Dottie:

I answered a request rather similar to this yesterday where the mtime might not be reliable and you want to use the date encoded in the filename.

Here is one solution just change the target directory.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: writing a script not going well

You will also need a copy of my date sledgehammer, caljd.sh. In the previous script note that the actual rm command is commented out so that you can safely test it.

Regards, Clay

If it ain't broke, I can fix that.