Operating System - HP-UX
1827822 Members
2551 Online
109969 Solutions
New Discussion

Filesystem Maintenance script help

 
SOLVED
Go to solution
George_Dodds
Honored Contributor

Filesystem Maintenance script help

Hi peeps.

One of my many shortcomings in wanting to be a 'proper' sysadmin is that i cant script for toffee...in other words i need some help.

Problem.

I have 2 archive filesystems that i have to clear down after i have backed them up,
/psnarchive and /pfx archive.
I use the following commands to list the large files within the filesystems ans sub directories

find /pfxarchive -size +10000000c -exec ll {} \;|more

find /psnarchive -size +10000000c -exec ll {} \;|more

Then i go through the directories and remove the files manually.

I would like to automate this process into a script to save time.

Any ideas

Cheers

George

5 REPLIES 5
Stefan Farrelly
Honored Contributor
Solution

Re: Filesystem Maintenance script help

If youre sure the find correctly finds only the files you want to delete then simply change the end of it to;

-exec rm -f {} \;

and it will find and remove in one go.
Im from Palmerston North, New Zealand, but somehow ended up in London...
F. X. de Montgolfier
Valued Contributor

Re: Filesystem Maintenance script help

Hi,

I may be too stupid to understand what you mean, but...

you've got it already! ;-)

find /pfxarchive -size +10000000c -exec rm {} \;

and
find /psnarchive -size +10000000c -exec rm {} \;

will remove automatically the files...

of course, if you've aliased rm to rm -i, may have to unalias it:
unalias rm

you could also use rm -f instead of rm, but that's a _bad_ idea if you're running the script as root ;-P
Cheers,

FiX
George_Dodds
Honored Contributor

Re: Filesystem Maintenance script help

Of course substitue the ll for rm!

I think i've been on the stupid pills again :)

Thanks for the quick response.

George
Bill Hassell
Honored Contributor

Re: Filesystem Maintenance script help

As with all good scripting techniques, don't re;y on the current environment (ie, aliasing). Change exec ll to exec /usr/bin/rm and all will be well. You can always override the aliased rm -i by adding -f to turn off the -i.

MOST IMPORTANT: find without the -type option will find everything (sockets, files, directories, links, device files, etc). Use -type f to limit the choices if these directories do (or may someday) contain directories. The rm command will fail to remove directories without the -r option, but this is a dangerous option for untested scripts.


Bill Hassell, sysadmin
Chris Vail
Honored Contributor

Re: Filesystem Maintenance script help

Usually when I do something like this, I want to log what files are removed. I do this as two steps, one using the find command to create a text file, and the second to parse the text file and actually remove the files. You can do these as two separate scripts or in a single script:
for FILE in `find /pfxarchive -size +10000000c -exec ll {} \`
do
echo $FILE>>LOGFILE
rm $FILE
done

This isn't very efficient, it could probably be done within the find command all by itself. But this one is easy to write and maintain.

Good Luck
Chris