Solved

Capture numeric result in Linux

Posted on 2011-09-26
6
285 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
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now