New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


SSH script for asterisk

Votes:

0

Your Vote:

Up

Down

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 by  kmorozov (50) 2 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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]



12 Replies

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  kmorozov (50) 2 1



Accepted Answer

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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

Created on Mar 21, 2017 12:11:22 PM by  kmorozov (50) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  kmorozov (50) 2 1

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



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

Same, it works fine: 0:200:running

Created on Mar 21, 2017 12:33:28 PM by  kmorozov (50) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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

Created on Mar 21, 2017 12:36:32 PM by  kmorozov (50) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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

Created on Mar 21, 2017 12:40:20 PM by  kmorozov (50) 2 1



Please log in or register to enter your reply.


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.