File detection then run script

I am currently running 4 scripts to complete a job for me. Each script requires the finished file of the one before it. For example the first script gets the finished file called model.x, then i would like script2 to start in and use model.x as the input and get model_min.x as the finished product and so on. Is there an easy way to get this to happen all at once? THanks

Hello,

You can check for existance of file using -f switch eg:

And so on.
-Nithin

does this only check once or keep checking until the file is detected because it takes abot 15 minutes for the file to be created once i start the job and the file is created for script2 to be ran?

My code checks only once. If you want to check periodically, pls use the function below

chk_File()
{
 wait_time=900 ;
 start_time=0 ;
 while [ $start_time -ge $wait_time ]
 do
  if [ -f $2 ]
  then
    echo "File found" ;
    ksh $1 ;
  fi
  start_time=`expr $start_time + 30` ;
done
}
chk_File script2.ksh file1.done
chk_File script3.ksh file2.done

My above function accepts 2 arguments. First one is the script to be called & second is the file from previous process. The function checks for file every 30 seconds until 15 mins(900 seconds). You can change them as per your need.
-Nithin.

Im sorry im trying to get this code to run but am failing to do so. Are the lines at the bottom of your code necessary to the script to run?

chk_File script2.ksh file1.done
chk_File script3.ksh file2.done

If so how do they relate to the $1 and $2.

Also how can i tell if the "while" command is working? Thanks so much

does your system support fuser? It reflects file access from various processes, and a zero count can be used to determine the file readiness...

For example:

while [[ $(fuser $file_in_use) ]] ;do echo "wait for it..." && sleep 30 ;done

Otherwise, lockfiles are always useful to serve as tie-lines for processes to check in and out with:

$ while [[ -e file_lock.txt ]] ;do echo "wait for it..." && sleep 3 ;done ;echo "done...d-done...done..."
done...d-done...done...
$ while [[ -e file_lock.txt ]] ;do echo "wait for it..." && sleep 3 ;done ;echo "done...d-done...done..."
wait for it...
wait for it...
wait for it...
wait for it...
wait for it...
wait for it...
done...d-done...done...