Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function monitor {
- echo "Monitoring another cam..."
- clear
- umount /mnt/videoserver
- mount -t cifs -o credentials=/var/smbcred //$SERVIP /mnt/videoserver
- echo "Stato del mount:"
- echo $(cat /proc/mounts | grep videoserver | tail -1 | awk '{print $1 " on " $2}')
- echo ""
- ALERTPATH=/home/alerts/$CAMERANAME.alert
- echo "Listing that dir..."
- ls "/mnt/videoserver/"
- echo "Now cd in that dir..."
- cd "/mnt/videoserver/"
- echo ""
- echo "Going in.."
- cd $(find . -maxdepth 1 -not -name '.*' -and -not -name '9*' -and -not -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
- pwd
- cd $(find . -maxdepth 1 -not -name '.*' -and -not -name '9*' -and -not -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
- pwd
- #cd $(find . -maxdepth 1 -not -name '.*' -and -not -name '9*' -and -not -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
- #echo ""
- echo "I'm in $(pwd) , ready to check"
- LASTMODTIME=$(stat -c %y $(pwd))
- echo "Folder last mod on: $LASTMODTIME"
- echo ""
- echo "||||||||||||||||||||"
- echo "Camera: $CAMERANAME"
- echo "Path: /mnt/videoserver/"
- echo "On: //$SERVIP"
- echo "Logfile: $ALERTPATH"
- echo ""
- echo "======="
- echo ""
- echo "Check if it is up..."
- ping -c 5 -i 0.2 $CAMIP > /dev/null 2>&1
- if [ $? -ne 0 ]
- then
- cat /dev/null > $ALERTPATH
- echo "Argh, camera looks down! Retrying..."
- ping -c 5 -i 0.2 $CAMIP > /dev/null 2>&1
- if [ $? -ne 0 ]
- then
- echo "It's really down!"
- echo "pingerr: camera did not answer" >> $ALERTPATH
- else
- cat /dev/null > $ALERTPATH
- echo "Yup! It's working!"
- echo "ok: camera answered" >> $ALERTPATH
- fi
- else
- cat /dev/null > $ALERTPATH
- echo "Yup! It's working!"
- echo "ok: camera answered" >> $ALERTPATH
- fi
- echo ""
- LASTOFUS=$(find . -type f -name "*.jpg" -mmin -2 -not -name ".*" -and -not -type d -and -not -name "INFO*" -exec ls -ltr {} + | tail -1 | awk '{print $9}')
- echo "Last modified file: $LASTOFUS"
- stat -c %y $LASTOFUS
- #UTIME=$(stat -c %y $LASTOFUS | awk '{print $2}')
- #IFS=: read H M SMS <<<"${UTIME##*-}"
- #MYTIME=$H$M
- #echo "Timestamp:"
- #echo $MYTIME
- #echo "Local timestamp:"
- #ULOCALTIME=$(date | awk '{print $5}')
- #IFS=. read H M S <<<"${ULOCALTIME##*-}"
- #MYLOCALTIME=$H$M
- #echo $MYLOCALTIME
- #echo ""
- echo "Courtesy Time: "
- date
- echo ""
- echo "===="
- echo ""
- #DIFF=$(expr $MYLOCALTIME - $MYTIME)
- # echo "Difference:"
- # echo $DIFF
- # echo ""
- echo "So $CAMERANAME status is..."
- if [[ -z "${LASTOFUS// }" ]]
- # if [[ $DIFF -ge 2 ]] || [[ $DIFF -le -1 ]]
- then
- if [[ $DISPLACED -ge 1 ]]
- then
- echo "NOREC"
- echo "recerror: camera is not recording!" >> $ALERTPATH
- DISPLACED=0
- echo "$CAMERANAME reported NOT recording ($LASTOFUS timestamp is $MYTIME) at $(date)" >> /root/errors.log
- sleep 5
- else
- echo "BAD sign, no recent files?"
- echo "Checking again in 30 secs..."
- sleep 30
- DISPLACED=1
- cd
- umount /mnt/videoserver
- monitor
- fi
- else
- DISPLACED=0
- echo "ok: camera is recording!" >> $ALERTPATH
- echo "REC"
- fi
- cd
- sleep 1
- umount /mnt/videoserver
- sleep 1
- }
Advertisement
Add Comment
Please, Sign In to add comment