echo "----The information of environment----" echo "CHECK_RETRY: $CHECK_RETRY" echo "SG90_WEB_STATUS: $SG90_WEB_STATUS" echo "--------------------------------------"
function func_send_log() { send_message $1 "$(date '+%Y-%m-%d_%H:%M:%S') 执行 check-hp-1106-printer.sh" }
function func_check_printer() { PRINTER_STATUS="$(lsusb | grep P1106 2>/dev/null)" echo "PRINTER_STATUS: $PRINTER_STATUS" if [ "${PRINTER_STATUS}" != "" ];then # 打印机正常,直接退出 exit 0 fi echo "The printer has been offline. Start to run sg90" if [ $SG90_WEB_STATUS != 200 ];then # 打印机 和 sg90 proxy 都不正常,没有必要在循环了,直接退出 func_send_log "[ERROR] 「打印机」和「SG90 Web」均离线。" exit 0 fi # 执行 sg90 curl -o /dev/null -s $SG90_WEB_GO # sg90 需要执行一段时间,所以停顿下 echo "wait 10s" sleep 10 }
while [ $CHECK_RETRY -gt 0 ] do echo "Start to retry..., $CHECK_RETRY" func_check_printer let CHECK_RETRY-- sleep $RETRY_INTERVAL if [ "${CHECK_RETRY}" = 0 ]; then func_send_log "[ERROR] 重试已达上限,打印机还在「离线」状态。" fi done