What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

SSH script for asterisk

Votes:

0

Hi, i need to check that asterisk trunk is active. I need to make 30 sensors with different trunk names. I ended up with such ssh script: #!/bin/bash var1=$1 if [ "$var1" == OK ] then echo "0:200:running" else echo "2:404:UNREACHABLE" fi

and i give this parameter to prtg "/usr/sbin/asterisk -rx "sip show peers" |grep 9859204943 |awk '{print $7}'| sed 2,2d"

What am i doing wrong? if i making script like this: #!/bin/bash var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep 9857617234 |awk '{print $7}'| sed 2,2d) if [ "$var1" == OK ] then echo "0:200:running" else echo "2:404:UNREACHABLE" fi

Everything is working fine, but in this case i need 30 different scripts, i need somehow to fill "Number" 9857617234 in the sensor parameters.

asterisk gsm ssh-script

Created on Mar 16, 2017 5:23:36 PM



Best Answer

Accepted Answer

Votes:

0

Hey kmorozov,

Please try to use the following script:

#!/bin/bash
value=$1
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:running"
else
 echo "2:404:UNREACHABLE"
fi

Does it work?

Created on Mar 21, 2017 12:00:43 PM by  Sven Roggenhofer [Paessler Technical Support]

Last change on Mar 21, 2017 12:00:58 PM by  Sven Roggenhofer [Paessler Technical Support]



14 Replies

Votes:

0

Hey kmorozov,

Thank you very much for your KB-posting.

Please try to use the following line:

var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep $1 |awk '{print $7}'| sed 2,2d)

instead of

var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep 9857617234 |awk '{print $7}'| sed 2,2d)

That way, you only need to commit the number "9859204943" as parameter in the sensor settings in PRTG.

Best regards,
Sven

Created on Mar 20, 2017 10:12:08 AM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

Thank you very much for reply, when I'm doing as u advised prtg always show error message, which means that script doesn't receive parameter. Maybe there is another way to make it without var1=$, or maybe I need to commit somewhere in the script.

Created on Mar 21, 2017 11:31:14 AM



Accepted Answer

Votes:

0

Hey kmorozov,

Please try to use the following script:

#!/bin/bash
value=$1
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:running"
else
 echo "2:404:UNREACHABLE"
fi

Does it work?

Created on Mar 21, 2017 12:00:43 PM by  Sven Roggenhofer [Paessler Technical Support]

Last change on Mar 21, 2017 12:00:58 PM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

No, only errors again. Maybe it because its value in value?

Created on Mar 21, 2017 12:11:22 PM



Votes:

0

Probably - when you run it manually, write $value to the console as well so you can see the actual value. Probably the wrong column is selected via awk or sed?

Created on Mar 21, 2017 12:14:28 PM by  Stephan Linke [Paessler Support]



Votes:

0

If I run script via console like this:

#!/bin/bash
value=9859204943
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:running"
else
 echo "2:404:UNREACHABLE"
fi

I receive 0:200:running as it should be, maybe some sensor settings is wrong ?

Created on Mar 21, 2017 12:20:40 PM

Last change on Mar 21, 2017 12:27:54 PM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

Could you execute the script like this: ./script.sh 9859204943

Remember to configure value to be $1 instead of the current numerical value. Same result?

Created on Mar 21, 2017 12:30:13 PM by  Stephan Linke [Paessler Support]



Votes:

0

Same, it works fine: 0:200:running

Created on Mar 21, 2017 12:33:28 PM



Votes:

0

So that means that the script sensor doesn't provide the correct value as parameter. Could you post the sensor config, specifically the parameter field?

Created on Mar 21, 2017 12:34:40 PM by  Stephan Linke [Paessler Support]



Votes:

0

I found the problem, in parameter field was "9859204943", it worked with '9859204943'

Created on Mar 21, 2017 12:36:32 PM



Votes:

0

Finally :-)

Glad to hear that you were able to solve the issue.

Wish you a great day.

Created on Mar 21, 2017 12:38:57 PM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

Thank you very much, this sensor will help me a lot.

Created on Mar 21, 2017 12:40:20 PM



Votes:

0

Hi, I have some issue..

My script running well in linux, but still unreachable on prtg..

this my script :

#!/bin/bash
value='callcentergif/callcenterg'
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:RUNNING"
else
 echo "2:404:UNREACHABLE"
fi

and this my prtg setting :

Parameters : -value 'callcentergif/callcenterg'

Anyone can help? Thanks

Created on Nov 27, 2019 6:46:03 PM

Last change on Nov 28, 2019 9:21:01 AM by  Stephan Linke [Paessler Support]



Votes:

0

The parameters in Bash don't work like this. Could you evaluate the issue further? What problem does the Sensor message disclose?

Created on Nov 29, 2019 9:14:25 AM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.