Operating System - HP-UX
1829582 Members
22037 Online
109992 Solutions
New Discussion

Re: Deleting spool files by creation date

 
SOLVED
Go to solution
Helga Skelly
Occasional Advisor

Deleting spool files by creation date

Our software runs batch jobs that produce "tail sheets". These tail sheets list warnings and errors. We are deferring the tail sheets in order to avoid paper waste. This presents another problem in that they need to be managed properly on the system. Periodically, we woudl like to remove tail sheets more than 90 days old. Is it possible to accomplish this in a script? Is anyone doing this and would you be willing to share your script file?
12 REPLIES 12
RAC_1
Honored Contributor
Solution

Re: Deleting spool files by creation date

I do not have the script ready, but find can be used easily in your case. You can set it through cron ti run at certain time and move files to other location/delete/what eer you want.

The command would be as follows.

find /path -type -mtime +90 -exec mv {} /dest \;

This would move files more than 90 days old to /dest dir.

Anil
There is no substitute to HARDWORK
Pete Randall
Outstanding Contributor

Re: Deleting spool files by creation date

Helga,

It's rather simple with the find command:

find /dirname -type f -name file_name* -mtime +30 -exec rm {} \;

or

find /dirname -type f -name file_name* -mtime +30 | xargs rm


Pete

Pete
Helga Skelly
Occasional Advisor

Re: Deleting spool files by creation date

Hi, Pete

I've been trying your first method. I am logged in as root:

find /ifas/xport/.spool -type f -name O*.data -mtime +90 -exec rm {}\;

I keep getting an error:
find: -exec not terminated with ';'
I do have the ';' at the end of the command line.

When I tried your second method, I got the error:
Usage: rm [-Rfir] file ...

What am I doing wrong?
RAC_1
Honored Contributor

Re: Deleting spool files by creation date

You need a space between {} and \;

Anil
There is no substitute to HARDWORK
Pete Randall
Outstanding Contributor

Re: Deleting spool files by creation date

Helga,

Anil is exactly right for the first method and I left something out of the second method. I think the second should be
find /ifas/xport/.spool -type f -name O*.data -mtime +90 | xargs rm {}


Pete

Pete
Helga Skelly
Occasional Advisor

Re: Deleting spool files by creation date

Pete,

Thank you for your solutions. I got the first method to work. However, for the second method even with the changes, I am still getting an error:

# find /ifas/xport/.spool -type f -name O*.data -mtime +1 | xargs rm{}
xargs: rm{} not found

I've tried it with a space betwwen rm and the {} and without...
Geoff Wild
Honored Contributor

Re: Deleting spool files by creation date

This is what I fo from cron:

0 5 * * 1 [ -d /var/adm/lp/XEBEC ] && /usr/local/bin/print.clean.receive >/dev/null 2>&1

The -d just makes sure the directory exists (cause I use MC/SG).

# cat /usr/local/bin/print.clean.receive
#!/bin/sh
# Script to remove old print jobs
# Geoff Wild
# April 4 2002
#
find /var/spool/lp/receive -name '*PRD' -mtime +7 -exec rm {} \; >/tmp/lp.receive.log
find /var/spool/lp/receive -name '*QA' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
find /var/spool/lp/receive -name '*DEV' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
find /var/spool/lp/receive -name '*VPR' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
find /var/adm/lp/XEBEC -name '*ftplog' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Helga Skelly
Occasional Advisor

Re: Deleting spool files by creation date

Thank you all for your assistance. I am still having problems using the command successfully. I'm no longer getting errors, but the files are not deleting. I am logged in as root, trying to delete spoolfiles in the /ifas/xport/.spool directory. Here is what I tried (not using dates, but the same idea using the find command in conjuction with a rm command):

# pwd
/
# find /ifas/xport/.spool -type f -name O*.data -exec rm{} \;
# ll /ifas/xport/.spool
total 54
-rw-rw---- 1 bsi bsi 0 Oct 13 14:05 -t
-rw-rw---- 1 bsi bsi 9272 Oct 13 14:57 O3027.data
-rw-rw---- 1 bsi bsi 5271 Oct 13 16:44 O3058.data
-rw-rw---- 1 bsi bsi 9797 Oct 13 16:50 O3065.data
drwxrwxrwx 2 bsi bsi 96 Jun 12 1999 tailsheets
-rw-rw---- 1 bsi bsi 14 Oct 15 2000 testfile
#

Could someone please take a look at this?
Geoff Wild
Honored Contributor

Re: Deleting spool files by creation date

Put the O*.data in quotes:

"O*.data"

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Helga Skelly
Occasional Advisor

Re: Deleting spool files by creation date

I tried the quotes, but the files still did not delete...

# pwd
/
# whoami
root
# find /ifas/xport/.spool -type f -name "O*.data" -exec rm{} \;
# ll /ifas/xport/.spool
total 54
-rw-rw---- 1 bsi bsi 0 Oct 13 14:05 -t
-rw-rw---- 1 bsi bsi 9272 Oct 13 14:57 O3027.data
-rw-rw---- 1 bsi bsi 5271 Oct 13 16:44 O3058.data
-rw-rw---- 1 bsi bsi 9797 Oct 13 16:50 O3065.data
drwxrwxrwx 2 bsi bsi 96 Jun 12 1999 tailsheets
-rw-rw---- 1 bsi bsi 14 Oct 15 2000 testfile
#
Do you have any other suggestions I could try?
Geoff Wild
Honored Contributor

Re: Deleting spool files by creation date

Yes - you need a space after the rm

before the {}

find /ifas/xport/.spool -type f -name "O*.data" -exec rm {} \;


Rgds...geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Helga Skelly
Occasional Advisor

Re: Deleting spool files by creation date

Yes! It worked! Thank you so much, Geoff.