|
Hi Ron,
Sorry, I guess I should have been a little more specific. I have a TEMP folder on the IFS that is used by various utilities to create extracts/reports in various formats (PDF, CSV, TXT, etc), these files are usually downloaded right away or at the very least within 24 hours via a user submitting a job to send them. I want to delete (almost) everything in the TEMP folder that is older than a week. Is there a command or utility that I can use to do this?
Use QShell's find command. QShell is a unix-like shell that's included on your OS/400 CDs, and costs nothing if you already have OS/400.
In QShell the FIND utility is used to locate files with certain attributes in the directory structure. So the following would find all of the files that haven't been accessed in 7 days in the /tmp/reports directory (or any of it's subdirectories):
find /tmp/reports -atime +7 -printThe output of one QShell command can be converted to parameters that are added on to the end of another command. This is done by piping the output to the xargs program.
find /tmp/reports -atime +7 -print | xargs rm -rfSo, if find woud list "file1.pdf" "file2.pdf" "file3.pdf" then xargs would build & run a command string that says:
rm -rf file1.pdf file2.pdf file3.pdfThe "rm" command is the Unix command for deleting (removing) a file. every parameter you pass to it will be deleted.
The only problem with this code is that there's a limit to the size of a single command-line in QShell. In V5R3 they expanded that limit dramatically, but it was a sharp limitation in older releases. If instead of using XARGS, you can have the FIND utility delete each file individually:
find /tmp/reports -atime +7 -exec rm -rf {} \;FIND will take everything between the "-exec" and the "\;" and it'll use it as a command. It'll replace {} with the name of the file, and it'll run the command.
So, in this case, it'll run "rm -rf file1.pdf" then, it'll run "rm -rf file2.pdf" and so on for every file that it finds.
This solution is MUCH slower than the XARGS one because it has to submit a new job to run a new command for every single filename, whereas XARGS ran all of the filenames in one job. But XARGS had that sharp limitation for the size of a single command line.
Note that any of these commands can be run from a CL program. For example:
STRQSH CMD('find /tmp/reports -atime +7 -exec rm -rf {} \;')In fact, if you're more comfortable with CL (as I suspect most iSeries people are) it might make sense to use QShell to write the filenames to a file, then you can process that file from CL.
CRTPF MYLIB/MYFILE RCDLEN(1000) STRQSH CMD('find /tmp/reports -atime +7 -print > + /QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYFILE.MBR')Now you have a file called MYFILE that contains the list of files. You can delete them:
LOOP: RCVF MONMSG CPF0864 EXEC(CHGVAR &DONE VALUE('1')) IF (&DONE *NE '1') DO RMVLNK OBJLNK(&MYFILE) GOTO LOOP ENDDOI'm pretty sure that I've explained all of this on this list several times, so please check the mailing list archives for more info.
http://archive.midrange.com --- Scott Klement http://www.scottklement.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.