ec20会有部分情况下,voice没有自动打开的情况 写个脚本定时检查处理

2024-07-25 02:58:53   工作备份

 

文件名 check_signal.sh

  1. #!/bin/bash
  2. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  3. # 检查 Asterisk 服务是否运行
  4. if ! pidof asterisk >/dev/null; then
  5. echo "Asterisk service is not running. Exiting..."
  6. exit 1
  7. fi
  8. check_device_state() {
  9. local device_name=$1
  10. local device_state=$(asterisk -rx "quectel show device state $device_name" | grep -E "State\s+:" | awk '{print $3}')
  11. echo "$device_state"
  12. }
  13. check_device_voice() {
  14. local device_name=$1
  15. local voice_state=$(asterisk -rx "quectel show device state $device_name" | grep -E "Voice\s+:" | awk '{print $3}')
  16. echo "$voice_state"
  17. }
  18. device_info=$(asterisk -rx "quectel show devices" | grep -E "\s99" | awk '{print $1}')
  19. for line in $device_info; do
  20. # 定义设备名称
  21. device_name=${line%% *}
  22. # 获取设备状态
  23. device_state=$(check_device_state "$device_name")
  24. # 判断设备状态是否为 Free
  25. if [[ $device_state == "Free" ]]; then
  26. echo "$device_name signal 99!"
  27. asterisk -rx "quectel restart now $device_name"
  28. fi
  29. done
  30. #检查voice是否开启
  31. device_info=$(asterisk -rx "quectel show devices" | grep -E "Free|Dialing" | awk '{print $1}')
  32. need_push=0
  33. for line in $device_info; do
  34. # 定义设备名称
  35. device_name=${line%% *}
  36. # 获取设备状态
  37. voice_state=$(check_device_voice "$device_name")
  38. #echo "$device_name Voice:$voice_state"
  39. # 判断设备状态是否为 Free
  40. if [[ $voice_state == "No" ]]; then
  41. echo "$device_name Voice not open"
  42. asterisk -rx "quectel restart now $device_name"
  43. sleep 2
  44. #尝试重启,再查一次
  45. voice_state=$(check_device_voice "$device_name")
  46. if [[ $voice_state == "No" ]]; then
  47. /etc/asterisk/sh/tell_qy.sh "$device_name Voice无法打开,触发禁用,尝试修复无效,请尝试手动插拔"
  48. asterisk -rx "quectel stop now $device_name"
  49. need_push=1
  50. fi
  51. fi
  52. done
  53. if [[ $need_push == 1 ]]; then
  54. sleep 2
  55. /etc/asterisk/sh/node_check.sh
  56. fi