verifying existence of multiple files

Hi,

I have unix script on solaris 5.10.

I have to verify existence of 3 files in path and sleep for 1 hour.

I have tried for 1 file:

if [ -f /path/filename ]

then

echo " File is found!"

sleep 3600
echo "time delayed"

fi

Please advice

Why not use a cron job that is run every hour and then checks the files?

I don't have any idea about cron job :frowning:

Can i use something like :

#!/usr/bin/ksh
if [ -f /path/file1 and -f /path/file2]

then

echo " File is found!"

sleep 300
echo "time delayed"

fi

how about

#!/bin/ksh
until [[ 1 -gt 2 ]]; do # infinite loop
status="found" # default to true
for i in file1 file2 file3; do
if [ ! -f $i ]; then
status="not found" # if one or more of the files doesn't exist set to false
fi
done
echo Files are ${status}.
sleep 5
done

if your requirement is to sleep for a defined time, only if ALL files exist:
in a ksh shell

 ( [[ -f file1 ]]; [[ -f file2 ]]; [[ -f file3 ]] )  && ( sleep 30;echo all files found ) || echo one or more files not found 

Thank you :slight_smile:

It is working

i have create one dir that have 3 files and my following script keep checking those file in every 10 sec

#!/usr/bin/ksh
DD=`date`
while :;
do
if [ -f ./tmp/tmp1.tmp -a -f ./tmp/tmp2.tmp -a -f ./tmp/tmp3.tmp ]; then

echo "File Exist $DD " >> ./log.tmp

else

echo "One of File Not exist $DD" >> ./log.tmp
fi
sleep 10
done

but i guess you need another script to kick of this script so if you even log off your machine it won't affect your script

#!/usr/bin/ksh

nohup ./file_check.ksh &

this script will kick off the file_check.ksh and terminate and it will keep record the log in the nohup.out and log.tmp

I hope this might help you out.

Thanks
Soni