" Asterisk already running on /var/run/asterisk/asterisk.ctl. Use
asterisk -r to connect.
trunkcheck.sh: line 15: -rx: command not found "
says that you are erroring on
$asteriskbin -rx "sip show peer $thistrunk" | grep Status | grep -wc OK
$asteriskbin should resolve to
and $thistrunk to $1 (your calling argument) Screamer
checkforit i set to the return of so the line sent to bash:-
/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status | grep -wc OK.
from bash yourself try without prejuduice
/usr/sbin/asterisk -rx “sip show peer Screamer”
/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status
/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status | grep -wc OK
hopefully you get the idea ( the script does works but personally it is a little inelegant for my taste, )
When you get a script working that only says something when there is a problem, then I suggest you make a cron job out of it, the granularity can be as little as a minute. By default any output will be automatically emailed to the default cron job owner’s email, no output, no email. Be aware that cron jobs run under /bin/sh, so you will need fully qualified program names and file names as /bin/sh has a far more restricted “path” than /bin/bash.
(see I told you you needed a bash tutorial )
so the cron job could be a very simple “one-liner”:-
/usr/sbin/rasterisk -x “sip show peers”|/bin/grep -r “^[a-z,A-Z]”|/bin/grep UNREACHABLE
which will only enail you if the peer name starts with a letter (your extensions won’t, make sure your trunks do), they are expected to be Reachable (OK) but they are UNREACHABLE
It will work for all your trunks at the same time, so if they all disapper, then it is probably your network.
Deconstruct by going left to right stopping before each “pipe” | character until you “get it”
You can synthesize it’s behavior with
/usr/sbin/rasterisk -x “sip show peers”|/bin/grep -r “^[a-z,A-Z]”|/bin/grep UNREACHABLE|mail [email protected]
as you play with it . .