Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Capture numeric result in Linux

Posted on 2011-09-26
6
Medium Priority
?
299 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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

618 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