Board logo

標題: cron job to detect dongle status [打印本頁]

作者: mcdull    時間: 2017-10-13 00:39     標題: cron job to detect dongle status

用左 3G dongle 幾個月..
發現, 佢隔一排, 可能兩三日就detect唔到枝usb..
重點係..... 我根本唔知.

而家想寫個cron job check下枝dongle仲係咪online, 唔係的話就email我同reboot.

但係 asterisk -rx "dongle show devices" | grep Free | grep dongle0
係我用root既console可以正常return value..
但係放左入cron job 就完全冇return..

點解呢....
作者: 角色    時間: 2017-10-13 09:38

是否cron的command和root的rw权限不一样?
作者: mcdull    時間: 2017-10-13 11:03

是否cron的command和root的rw权限不一样?
角色 發表於 2017-10-13 09:38



    cron job 已經係用root行.

sudo crontab -e
我成個console都係root. 用緊 Freepbx

不過我個cron issue reboot command 佢都冇理我. 我都唔知點解
作者: ttmuskie    時間: 2017-10-15 21:02

Only reboot not work? How about the email?
作者: mcdull    時間: 2017-10-16 09:17

Only reboot not work? How about the email?
ttmuskie 發表於 2017-10-15 21:02


Email works. But asterisk -rx returns nothing, so it keeps warning me that my dongle disconnects.
作者: ttmuskie    時間: 2017-10-16 12:30

Try to specify the full path for the asterisk (i.e. /usr/sbin/asterisk) to see if it make any difference.
作者: mcdull    時間: 2017-10-17 23:13

Try to specify the full path for the asterisk (i.e. /usr/sbin/asterisk) to see if it make any differ ...
ttmuskie 發表於 2017-10-16 12:30



    did it already.  it doesn't return any error message. Just empty string.
作者: ttmuskie    時間: 2017-10-20 09:38

本帖最後由 ttmuskie 於 2017-10-20 09:40 編輯

I put this under my "sudo crontab -e":
  1. */5  *      *        *   *  /usr/sbin/asterisk -rx "dongle show devices" | grep Free | grep dongle0 | tee /tmp/tbd.txt
複製代碼
And the result:
  1. cat /tmp/tbd.txt
  2. dongle0      0     Free       8    0    0       PCCW-HKT       E180       11.126.13.00.380  354241028919407  454196220366839  Unknown
複製代碼

作者: mcdull    時間: 2017-10-22 04:16

隔左幾日, 無端端又會得左.....
作者: mcdull    時間: 2017-11-20 10:24

  1. #!/bin/sh

  2. #check if chan_dongle is actually loaded or quit
  3. checkchan=`/usr/sbin/asterisk -rx "dongle show devices" | grep dongle`
  4. if [[ $checkchan ]]; then
  5.    echo "`date`"
  6.    echo "chan_dongle is up and running"
  7.    echo "$checkchan"
  8. else
  9.    echo "`date`"
  10.    echo "chan_dongle has not been loaded, wait for next cronjob"
  11.    exit 0
  12. fi

  13. line=`/usr/sbin/asterisk -rx "dongle show devices" | grep +852XXXXXXXX | grep Free`
  14. deb=`/usr/sbin/asterisk -rx "dongle show devices"`
  15. if [[ $line ]]; then
  16.    echo "Hello Card is working fine"
  17.    echo "$line"
  18. else
  19.    echo "GSM down. Rechecking in 2 minute"
  20.    sleep 2m
  21.    line=`/usr/sbin/asterisk -rx 'dongle show devices' | grep +852XXXXXXXX | grep Free`
  22.    if [[ $line ]]; then
  23.       echo "Hello Card is working fine Now"
  24.       echo "$line"
  25.       exit 0
  26.    else
  27.       echo "GSM down. Rebooting in 1 minute"
  28.       echo $deb | mailx -s 'GSM unresponsive. System Reboot in progress' -r 'xxx@xxx.com' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com
  29.       /usr/sbin/shutdown -r 1
  30.    fi
  31. fi
  32. exit 0
複製代碼





歡迎光臨 電訊茶室 (http://telecom-cafe.com/forum/) Powered by Discuz! 7.2