-homework:
- Every five minutes Monitor incoming directory - send an alert if there is any
file present in incoming directory older than 5 minutes with outputof pwd and ls -lrt. - Every five minutes monitor Failed and Processing directory - send an alert if there is
any file present in processed or Failed directory with output of pwd and ls -lrt
-here iam having issue that even when there is no file present the count coming is 1 and if there is file present it is coming 0
-code which i tried:
#!/bin/bash
while true
do
for dir in `cat /home/dirlist.cfg`
do
cd $dir
find ${dir} -maxdepth 1 -mmin +5 -type f | xargs ls -lrt > $HOME/5_minoldfile.txt
export cnt=`grep -v "^$" $HOME/5_minoldfile.txt| wc -l`
echo $cnt
if [ "${cnt}" -gt 0 ];then
export dirtype=`echo $dir |awk -F "/" '{print $NF}'`
echo "$dirtype"
if [ $dirtype == "in" ]; then
echo "******* file in $dir is is not picked up for processing for more than 5 minutes please check**********"
cat $HOME/5_minoldfile.txt
mail -s "File Monitor" ng@abc.com < $HOME/5_minoldfile.txt
fi
fi
done
rm $HOME/5_minoldfile.txt
sleep 300
done