reformatting directory files

reformatting directory files

Post by Jim Denn » Wed, 03 Sep 1997 04:00:00





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
> automatically?

        cron?

Quote:> 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.

        So -- make that into a script, call the script from a
        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
        something like:

                T=/where/ever

                while [ -f $T/mydir.LCK ] sleep 5

                touch $T/mydir.LCK
                        mv $T/mydir $T/mydir.tmp.$$
                        mkdir $T/mydir
                rm $T/mydir.LCK
                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"
        wrapper).

        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
 
 
 

1. Reformatting a file

Hi,

I need to reformat an existing tab-delimited file programatically -
using Shell or awk or sed. The input file is in the following format-

Input File :
---------------------------
Object 1234

Field_ID    Field_Name    Field_Value
19             IP Address      10.44.22.34
20             Subnet Mask    255.255.247.0

Object 1235

Field_ID    Field_Name    Field_Value
19             IP Address      10.44.22.34

Object 1245

Field_ID    Field_Name    Field_Value
20             Subnet Mask    255.255.247.0
21             MAC_ADDR  08:00:03:05:02:05

.....etc
----------------------------

The output file tab-delimited format will be as shown which is a
grouping of the above fields -

-------------------------------------------
Object    IP Address    Subnet Mask

1234      10.44.22.34   255.255.247.0
1235      10.44.22.34
1245                            255.255.247.0
....etc
--------------------------------------------
For some Objects, the IP Address or Subnet Mask entries may not be
present and I need to fill in blank spaces for these.

Could someone please point me on how to do this. Any pointers will be
appreciated. Thanks in advance.

Regards,
Sudhir.

2. Linux & ftape runs and crashes

3. Reformat file, tricky.

4. client IP address?

5. what is fastest way to reformat file from variable to fixed length

6. RFCOMM BUG - Modules Refcount - 2.5.73

7. Help Needed to Reformat a File

8. Frequently Asked Questions about Unix (index) [Biweekly posting]

9. Sed Question - File Reformat

10. Reformatting file before ftp transfer

11. propagating directory perms to new files in that directory

12. Script that recurses through all directories tries to check file/directory named "*"

13. Login Error -- getcwd: cannot access parent directories: No such file or directory