I'm doing a script to see if a certain device writes on the disk or not. I ended up with this:
cd
mkdir -p /var/logfiles
CAMERANAME="tvcc16"
DIR='/share/HDA_DATA/video4/' #tvcc16
ALERTPATH="/var/logfiles/$CAMERANAME.alert"
while true; do
FILE_IS_WRITTEN=0
echo "$FILE_IS_WRITTEN" > /var/f_is_w
inotifywait -r -t 30 $DIR -e create |
while read path action file; do
echo "Written '$file' in '$path' via '$action'." | grep jpg | grep -v "INFO"
FILE_IS_WRITTEN=1
echo "$FILE_IS_WRITTEN" > /var/f_is_w
done
FILE_IS_WRITTEN=$(cat /var/f_is_w)
rm -rf /var/f_is_w
if [ $FILE_IS_WRITTEN -eq 0 ]
then
echo "NOREC (Status: $FILE_IS_WRITTEN)"
echo "recerror: camera is not recording!" > $ALERTPATH
else
echo "REC (Status: $FILE_IS_WRITTEN)"
echo "ok: camera is recording!" > $ALERTPATH
fi
done
The problem is that every time the cycle restart, inotifywait has to set up watches again. It's resource and time expensive... Is there a way to avoid this?