cron?Quote:> Hi there,
> I use the same directory very intensely over and over again
> ( Say 600 moves to and fro each day. )
> The size of this directory file growed from 512 bytes initially
> to 247808 bytes now.
> Is there a Unix (system manager) tool to make directories neat
So -- make that into a script, call the script from aQuote:> I only know the following 'trick':
> - move all the files to a new directory,
> - remove the old directory,
> - rename the new directory to the old one.
cron job. Presto, your very own "trick" sysadmin tool --
built precisely to your requirements and specifications.
A couple of hints:
You might want to do a simple filelocking trick between your
cron job (script) and any of the scripts or programs that
use this directory. Have your "dircompactor" script do
while [ -f $T/mydir.LCK ] sleep 5
mv $T/mydir $T/mydir.tmp.$$
mv $T/mydir.tmp.$$/* $T/mydir
rmdir $T/mydir.tmp.$$ || mail_error_message
## where mail_error_message is a shell function
## you might define to deal with a
This could use some work. You could have all programs that use
this directory write their PID into the lock file and use
ps to test for "stale" lock files. You could add traps to
automatically clean up the lock file in the event of some other
error, and/or a clause to deal with a lock file that never goes
away (perhaps by just mailing an error message).
If, on the other hand, you are pretty sure that the processes
will never collide -- your 600 directory entry creations and
removals will never happen while the cron job is running --
you can just skip all of the locking stuff.
Of course if your activity in this directory is already limited
to a single process or is orchestrated or synchronized by some
single process -- you can skip the cron job altogether -- and
add this to the "master" program (as a "clean up" or "preparation"
That is the hard part of any automation and scripting. Asking
all the "what if's" that you implicitly account for when you do
something by hand.
--Quote:> Many thanks in advance,
> Yours sincerelly,
> Frank Brugman
Proprietor, Starshine Technical Services: http://www.starshine.org
Key fingerprint = 2524E3FEF0922A84 A27BDEDB38EBB95A