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..
點解呢.... 是否cron的command和root的rw权限不一样? [quote]是否cron的command和root的rw权限不一样?
[size=2][color=#999999]角色 發表於 2017-10-13 09:38[/color] [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=43822&ptid=7041][img]http://www.telecom-cafe.com/forum/images/common/back.gif[/img][/url][/size][/quote]
cron job 已經係用root行.
sudo crontab -e
我成個console都係root. 用緊 Freepbx
不過我個cron issue reboot command 佢都冇理我. 我都唔知點解 Only reboot not work? How about the email? [quote]Only reboot not work? How about the email?
[size=2][color=#999999]ttmuskie 發表於 2017-10-15 21:02[/color] [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=43824&ptid=7041][img]http://www.telecom-cafe.com/forum/images/common/back.gif[/img][/url][/size][/quote]
Email works. But asterisk -rx returns nothing, so it keeps warning me that my dongle disconnects. Try to specify the full path for the asterisk (i.e. /usr/sbin/asterisk) to see if it make any difference. [quote]Try to specify the full path for the asterisk (i.e. /usr/sbin/asterisk) to see if it make any differ ...
[size=2][color=#999999]ttmuskie 發表於 2017-10-16 12:30[/color] [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=43826&ptid=7041][img]http://www.telecom-cafe.com/forum/images/common/back.gif[/img][/url][/size][/quote]
did it already. it doesn't return any error message. Just empty string. [i=s] 本帖最後由 ttmuskie 於 2017-10-20 09:40 編輯 [/i]
I put this under my "sudo crontab -e":[code]
*/5 * * * * /usr/sbin/asterisk -rx "dongle show devices" | grep Free | grep dongle0 | tee /tmp/tbd.txt
[/code]And the result:[code]
cat /tmp/tbd.txt
dongle0 0 Free 8 0 0 PCCW-HKT E180 11.126.13.00.380 354241028919407 454196220366839 Unknown
[/code] 隔左幾日, 無端端又會得左..... [code]#!/bin/sh
#check if chan_dongle is actually loaded or quit
checkchan=`/usr/sbin/asterisk -rx "dongle show devices" | grep dongle`
if [[ $checkchan ]]; then
echo "`date`"
echo "chan_dongle is up and running"
echo "$checkchan"
else
echo "`date`"
echo "chan_dongle has not been loaded, wait for next cronjob"
exit 0
fi
line=`/usr/sbin/asterisk -rx "dongle show devices" | grep +852XXXXXXXX | grep Free`
deb=`/usr/sbin/asterisk -rx "dongle show devices"`
if [[ $line ]]; then
echo "Hello Card is working fine"
echo "$line"
else
echo "GSM down. Rechecking in 2 minute"
sleep 2m
line=`/usr/sbin/asterisk -rx 'dongle show devices' | grep +852XXXXXXXX | grep Free`
if [[ $line ]]; then
echo "Hello Card is working fine Now"
echo "$line"
exit 0
else
echo "GSM down. Rebooting in 1 minute"
echo $deb | mailx -s 'GSM unresponsive. System Reboot in progress' -r 'xxx@xxx.com' -S smtp='xxx.xxx.xxx.xxx' xxx@xxx.com
/usr/sbin/shutdown -r 1
fi
fi
exit 0
[/code]
頁:
[1]