File Watcher

Hi

Please help me in this

I want to execute a shell script abc.ksh.
But I only want it to execute if file XYZ is not present.
If file XYZ is present than I want to unix to sleep for 5 Sec and than agaian check for XYX existence.
if it sleeps for more than 30 seconds ( 6 time )I want it to fail.

I am not good at UNIX.
I work in different technology
help will be appreciated.

file=XYZ
n=0
while [ -f "$file" ]
do
  sleep 5 &
  n=$(( $n + 1 ))
  [ $n -ge 6 ] && exit 1
  wait
done
abc.ksh

Hi there!

I guess You mean that You want to run it, but only perform a specific operation if the file exists?
You can try this, modify it to Your needs,

retries=0
while true ; do
    if [ -f XYZ ]; then
        echo found file, performing operation and exiting
        #more operations here
        break
    fi
    retries=$((retries+1))
    [ $retries -eq 7 ] && break
    echo waiting for file...
    sleep 5
    echo retries=$retries
done

Why should that be as

can't it be just as

sleep 5

?