Whenever files in count
directory changes, I need to calculate the total count
and if the total count
is between 50 and 100, I need to run a script with input N
- which takes only 1 sec to run.
The problem is when the total count
increases each time from 50 to 100, the script is executing each time. Is there a way to stop the loop/script from running the second time?
while inotifywait -r -e modify $dir
do
line=$(grep -ho '[0-9]*' /var/count* | awk '{sum+=$1} END {print sum}')
echo "********** count is $line **********"
if [ $line -ge 50 ] && [ $line -lt 100 ]
then
echo "_____________executing if 1 _______________"
export N=1
/var/test.sh
fi
if [ $line -ge 100 ] && [ $line -lt 150 ]
then
echo "_____________executing if 2 _______________"
export N=2
/var/test.sh
fi
done