Solved

Capture numeric result in Linux

Posted on 2011-09-26
6
296 Views
Last Modified: 2012-05-12
I am running a few Asterisk servers and I would like the run a daily cron job to check and see how many sip peers are resisted on my servers.  Currently we are only able to do this manually which can be a lot of work.  Below is the command we run which shows the result.

COMMAND: /usr/sbin/asterisk -rx "sip show peers" | grep "sip peers"
RESULT: 901 sip peers [Monitored: 22 online, 4 offline Unmonitored: 771 online, 104 offline]

I need some help with a script that will run the above command, read the first number into a numeric variable (example: 901 above.  This will always be between 0 and 1,500), and then process an IF statement to send me an email alert once the value is above 1,300.

Thanks
0
Comment
Question by:ipconfig610
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:tmwsiy
ID: 36599102
This should work with integer strings

this=14
that=16

if [ $this -gt $that ]
then
fi
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36599146
if [[ $( /usr/sbin/asterisk -rx "sip show peers" | grep "sip peers" |awk '{print $2}') -gt 1300 ]]; then
 date > mail -s "No. of SIP Peers above 1.300" ipconfig610@his.domain.tld
fi

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36599166
Sorry, typo

date | mail -s "No. of SIP Peers above 1.300" ipconfig610@his.domain.tld
0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

Author Comment

by:ipconfig610
ID: 36599539
when I run:
sudo /usr/sbin/asterisk -rx "sip show peers" | grep "sip peers" |awk '{print $2}'

the result only returns:
sip



0
 
LVL 19

Expert Comment

by:xterm
ID: 36599588
Change the $2 to $1 in the command, and it will work.

Your original post made it look as if the word "RESULT:" was part of the result, which is why the suggestions above are grabbing the 2nd field instead of the first.
0
 

Author Comment

by:ipconfig610
ID: 36599723
my mistake.  I have never used the  'awk' command before.  That changed worked perfectly.

Thanks!
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question