I have a script which loops a directory to find the file. right now, I want to add time interval which means every 15 minutes it checks the dir once. if all files are found, then exit with 0. if there are some files missing at 6:00am the process exit with 20. the script start at 7:00pm everyday by third part scheduler.
My current script like:
IFS=","
while read group file X
do
if [ -f $file ] ; then
time=$(ls -l $file |awk '{print $6,$7,$8}')
echo "$group, $file, $time, YES"
else
echo "$group, $file , NO"
fi
done < list.txt
This is I want, but I don't know how to implement this into my existing code. would you please give me a sample. (I need sleep 900 seconds and checking if the time is 6:00 AM or after 6:00AM, if yes, the script stops checking)
I tired below code: but I don't know how to check if the time is 6:00AM or later. would you please give me some help.
while :
do
time1=`date +"%d-%m-%Y:%T"`
echo "Start time: " $time1
sleep 60
time2=`date +"%d-%m-%Y:%T"`
echo "End time: " $time2
done
while :
do
IFS=","
while read group file X
do
if [ -f $file ] ; then
time=$(ls -l $file |awk '{print $6,$7,$8}')
echo "$group, $file, $time, YES"
else
echo "$group, $file , NO"
fi
done < list.txt
sleep 900
echo " 900 sec over start script again"
done
Thanks for you quick reply.
I have one more question: how could I check if current time is 6:00AM over or not, because I need exits with error code after 6:00AM, if there are still some file missing.
I think RudiC's long line may have been truncated.
I also think the following may do what you want on a SunOS system, but since you didn't supply any sample of your list.txt file contents, I can't make any guarantees.
#!/bin/ksh
while hour=$(date +%H)
do if [ $hour -ge 6 ] && [ $hour -lt 19 ]
then exit 20
fi
all_found=1
while IFS="," read group file X
do if [ -f "$file" ]
then time=$(ls -l "$file" | nawk '{print $6,$7,$8}')
printf "%s,%s,%s,YES\n" "$group" "$file" "$time"
else all_found=0
printf "%s,%s,NO\n" "$group" "$file"
fi
done < list.txt
if [ $all_found -eq 1 ]
then exit 0
else sleep 900
fi
done