2,540 pts.
 delete old IFS files
I have been asked to create an automatic procedure which cleans out (ie delete) files older than 6 months. Transactionfiles keep coming into the system, and after having been processed (read) they are moved to an IFS directory 'archive'. We now have more than 90.000 files from last 26 months. I have considered various solutions like 'ls' to a file, and then read via pgm and execute delete, BUT something tells me that there is a better solution. I would like to do the job from a CL-pgm using STRQSH with some 'rm' command, but I got stuck in my investigations. Pls give me some thoughts on how to do this smart.

Software/Hardware used:
system i, v6r4
ASKED: June 9, 2010  1:49 PM
UPDATED: December 22, 2011  12:06 AM

Answer Wiki:
Hi, You can try to check out this link. <a href="http://www.mcpressonline.com/programming/rpg/tips-and-techniques-delete-old-spool-files.html"> Good luck, YuVa47
Last Wiki Answer Submitted:  June 10, 2010  4:06 pm  by  YuVa47   1,285 pts.
All Answer Wiki Contributors:  YuVa47   1,285 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

If you have TAATOOLS, that has a couple options for deleting old files in an IFS directory

 880 pts.

 

After a lot of investigation, I got created the one-statement-solution to my question.
Since no one amongst you seems to know what I found out, I’ll teach you the trick.

If you insert the directory-path of the directory to search/delete old files into the following CL-statement the command will do the job of deleting fils older than 180 days.

STRQSH CMD('find [mydirpath] -type f -mtime +180 | xargs rm')

In short: the QSHELL command ‘find’ creates an internal list of files older than 180 days; – the lst is ‘piped’ (passed) to the delete-function (‘xargs rm’). Of course the 180-number may be changed to other values.

Yet another proof tht we are working on a great machine – it also runs unix-commands :-)

PS: Some may prefer two lines of code:

CD [mydirpath]
STRQSH CMD('find . -type f -mtime +180 | xargs rm')

best rgds
DanF

 2,540 pts.

 

…for some reason my one-line solution got lost in the prev entry; – here it is again:

STRQSH CMD(’find [mydirpath]  -type f -mtime +180 | xargs rm’)
 2,540 pts.

 

well… here it is with no use of the editorscode/code function:

STRQSH CMD(’find [mydirpath] -type f -mtime +180 | xargs rm’)

 2,540 pts.

 

when I use the below line in CL:
STRQSH CMD(‘find /MRTEST -type f -mtime +30 | xargs rm’)
I get the folowwing error when I run it:
find: 001-2187 The option -TYPE is not valid.

 10 pts.

 

Miker,
I tried to copy/paste your statement onto a 5250 commandline; the beginning and ending apostrophes were displayed as a dark rectangle; – this made me wonder about codepage !!!
Well, having replaced your directory (‘/MRTEST’) with a directory that exists on my box, and replaced the two errorneous rectangle characters (x’1A’) with apostrophes, and removed the piping of data (‘| xargs rm’), the statement looked like this:

STRQSH CMD('find /wpa/ARKIV/WPA2ERP -type f -mtime +30')

I pressed the Enter key, and the stement was executed without errors.
Without the piping of the data, the data is simply displayed on screen.

I have no exact answer to your question, but maybe the following could be investigated:

1. os400 release level and ptf-level.

2. is your apostrophs the right character ?? study this carefully:
Your statement copy/pasted:

STRQSH CMD(’find /MRTEST -type f -mtime +30 | xargs rm’)

..and the same code with an extra apostroph addet to the last apostroph of yours:

STRQSH CMD(’find /MRTEST -type f -mtime +30 | xargs rm’')

I copy/pasted directly in browserenvironment. Look carefully, – your apostroph and the one I entered are not the same…

3. How did you enter the statements? – on a PC with copy/paste to 5250… try keying in the statement directly on a 5250 commandline.

Pls report back, and I’ll try to help you.

DanF

 2,540 pts.

 

Sorry, – the editor changed th look of my apostroph next to your ditto. Here it is again :

STRQSH CMD(’find /MRTEST -type f -mtime +30 | xargs rm’’)

 2,540 pts.

 

find: 001-2187 The option -TYPE is not valid.

What is your OS version? What is your cume PTF level?

If you run the same utility from a QSH command line, does the same error occur? (Copy/paste it if possible.)

Tom

 108,260 pts.

 

Whenever working with multiple systems (different browsers, different PCs, copy/paste into emulators, any combination), things like quote marks can be a pain. See the Wiki article on Quotation mark glyphs for background. ‘Smart’ quotes? Yeah, right.

Tom

 108,260 pts.

 

It appears that you have a very nice solution and I just wanted to point out that you could also perform the deletion using various APIs called by an application program. The application program could then also provide audit reports, “make decisions” based on varous attributes of the file, etc. A series of articles on this can be found here.

 6,055 pts.