文件名 check_signal.sh
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 检查 Asterisk 服务是否运行
if ! pidof asterisk >/dev/null; then
echo "Asterisk service is not running. Exiting..."
exit 1
fi
check_device_state() {
local device_name=$1
local device_state=$(asterisk -rx "quectel show device state $device_name" | grep -E "State\s+:" | awk '{print $3}')
echo "$device_state"
}
check_device_voice() {
local device_name=$1
local voice_state=$(asterisk -rx "quectel show device state $device_name" | grep -E "Voice\s+:" | awk '{print $3}')
echo "$voice_state"
}
device_info=$(asterisk -rx "quectel show devices" | grep -E "\s99" | awk '{print $1}')
for line in $device_info; do
# 定义设备名称
device_name=${line%% *}
# 获取设备状态
device_state=$(check_device_state "$device_name")
# 判断设备状态是否为 Free
if [[ $device_state == "Free" ]]; then
echo "$device_name signal 99!"
asterisk -rx "quectel restart now $device_name"
fi
done
#检查voice是否开启
device_info=$(asterisk -rx "quectel show devices" | grep -E "Free|Dialing" | awk '{print $1}')
need_push=0
for line in $device_info; do
# 定义设备名称
device_name=${line%% *}
# 获取设备状态
voice_state=$(check_device_voice "$device_name")
#echo "$device_name Voice:$voice_state"
# 判断设备状态是否为 Free
if [[ $voice_state == "No" ]]; then
echo "$device_name Voice not open"
asterisk -rx "quectel restart now $device_name"
sleep 2
#尝试重启,再查一次
voice_state=$(check_device_voice "$device_name")
if [[ $voice_state == "No" ]]; then
/etc/asterisk/sh/tell_qy.sh "$device_name Voice无法打开,触发禁用,尝试修复无效,请尝试手动插拔"
asterisk -rx "quectel stop now $device_name"
need_push=1
fi
fi
done
if [[ $need_push == 1 ]]; then
sleep 2
/etc/asterisk/sh/node_check.sh
fi