Urgent Help needed !!!

Hi,

I have a directory, where i get 4 files for each day... The files will be generated at any time. I am trying for a shell script for copying the file from this directory whenever new file is generated.

Say for example : If the directory X has following files A1,A2,A3,A4,B1,B2,B3,B4... and for today C1,C2,C3,C4 files will get generated. Once the C1 gets generated in the directory X means immediately it should be copied to my home path....

Please give me some logic/clues for writing the script...

[Wrong forum... moving jmc]

The OS can't tell something immediately when a file is created. You have to just keep checking. (Linux has the inotify system, but it's necessary to compile a C program to use that.)

#!/bin/sh

# Which foldername to watch for
WATCHFOR='A'

while true
do
        # Look for A1, or B1, or C1, etc.  Check every second.
        while [ ! -d ${WATCHFOR}1 ]
        do
                sleep 1
        done

        echo cp -R ${WATCHFOR}[0-9] /path/to/dest

        # Turn A into B, B into C, ... Y into Z, Z into A.
        WATCHFOR=$(echo "$WATCHFOR" | tr '[A-Z]' '[B-ZA]')
done

Solaris with DTrace can :wink: