shell script to check availability of a file for 1 hour , after one hour if file not there , it will echo "Time Out"
by subir from LinuxQuestions.org on (#50FYD)
i wrote this code. but the problem is after every 300s it prints "Time over", when $fname present is got out from the loop. I want "time over" after 1hr if file not arrived, but after 300s it starts to print "time over"
#!/bin/bash
echo "enter file name"
read fname
START=`date +%s`
while [ $(( $(date +%s) - 3600 )) -lt $START ]; do
if [ -e $fname ]
then
echo "$fname present"
break
sleep 300
else
echo "Time Over"
fi
done


#!/bin/bash
echo "enter file name"
read fname
START=`date +%s`
while [ $(( $(date +%s) - 3600 )) -lt $START ]; do
if [ -e $fname ]
then
echo "$fname present"
break
sleep 300
else
echo "Time Over"
fi
done