check_rtsp.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. source /etc/profile
  3. # 网络摄像头自检
  4. ip="$rtspip"
  5. date="`date '+%Y-%m-%d %H:%M:%S'`"
  6. lost_rate=`ping -c 8 -w 8 $ip | grep 'packet loss' \
  7. | awk -F'packet loss' '{ print $1 }' \
  8. | awk '{ print $NF }' | sed 's/%//g'`
  9. if [ ! -d "/opt/datas/log/network" ]; then
  10. mkdir -p /opt/datas/log/network
  11. fi
  12. if [ $lost_rate -eq 0 ]
  13. then
  14. echo "rtsp ok"
  15. ps -ef | grep "gsd" | grep -v "grep"
  16. if [ $? -eq 1 ]
  17. then
  18. echo "Rtsp服务恢复,重启服务! $date" >> /opt/datas/log/network/check_rtsp.log
  19. cd /opt/GSD/
  20. docker-compose up -d
  21. else
  22. echo "服务正常 $date" >> /opt/datas/log/network/check_rtsp.log
  23. fi
  24. elif [ $lost_rate -le 100 ]
  25. then
  26. echo "rtsp error"
  27. ps -ef | grep "gsd" | grep -v "grep"
  28. if [ $? -eq 1 ]
  29. then
  30. echo "rtsp服务异常,等待服务恢复 $date" >> /opt/datas/log/network/check_rtsp.log
  31. else
  32. cd /opt/GSD/
  33. docker-compose stop
  34. echo "rtsp摄像头异常,等待摄像头服务正常后重启服务! $date" >> /opt/datas/log/network/check_rtsp.log
  35. fi
  36. fi