1833406 Members
2925 Online
110052 Solutions
New Discussion

script problem.

 
Jeffrey F. Goldsmith
Super Advisor

script problem.

I have a cron job that runs every morning on my servers. This script cleans out old files from folders in the /tmpspool folder. I have been using this script for the past 5 years on the server with HP-UX 11.0 with out any problems. When I run this script on my server that has HP-UX 11.23 the folders get changed to files. What has changed with the new version of HP-UX that would cause this? Is there a way to correct this so I can have the folders cleaned out?

Here is the part of the script that runs in the cron file:

touch /tmpspool/.stdlist /tmpspool/err /tmpspool/download /tmpspool/fxpress /tmp
spool/payrpts /tmpspool/payxtracts /tmpspool/workcomp
ll -d /tmpspool/.stdlist /tmpspool/err /tmpspool/download /tmpspool/fxpress /tmp
spool/payrpts /tmpspool/payxtracts /tmpspool/workcomp
rm -rf `find /tmpspool -mtime +2`

5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: script problem.

Jeffrey,

Just out of curiosity, I would try:

find /tmpspool -type f -mtime +2 |xargs rm

rather than your "rm -rf `find /tmpspool -mtime +2`". You may or may not want to omit the "-type f", depending on whether you wish to remove directories as well as files.


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: script problem.

First, never ever refer to "directories" as "folders" in a UNIX environment. "Folder" has no meaning and immediately marks you as one of those people from an OS in a galaxy far, far away.

The behavior of touch has not changed. Touch will merely update the timestamp of an an existing file (and do nothing else). Note that in UNIX speak, a file might be a regular file, a directory, a device node, among others but touch will never transform a directory file into a regular file. What is actually happening is that some of these files do not exist and touch dutifully creates them as regular files. You need to add a test to see if the files (again, think directory files) in your list exist and, if not, do a mkdir before touch is ever executed.
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: script problem.

Shalom,

HP-UX 11.23 is much more advanced than 11.00.

But what you are describing is core functionality that should not have changed.

You say you've posted part of the script that runs in the cron file. Is it possible that some other part of the script is erroring out?

Try putting a set -x in the top of the script and running it manually. You may find the problem this way.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: script problem.

Hi Jeff:

Nothing has changed really. You aren't being very rigourous in your selections.

First, use '-type f' with your find if you truly only want *files* removed and not their parental directories.

Regardless of that, use '-depth' which causes 'find' to examine the _contents_ of directories it visits _before_ examining the directory! The act of deleting a file in a directory will update the directory's 'mtime' and thus the directory will not be a candidate for selection.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: script problem.

>Clay: You need to add a test to see if the files (again, think directory files) in your list exist and, if not, do a mkdir before touch is ever executed.

You can always use mkdir -p and you don't need to test before the touch.