?
Solved

Capture numeric result in Linux

Posted on 2011-09-26
6
Medium Priority
?
297 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

764 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