Operating System - Linux
1753989 Members
6210 Online
108811 Solutions
New Discussion

Help required in shell script

 
SOLVED
Go to solution
Mampi_Mumbai
Regular Advisor

Help required in shell script

Dear Experts,

I want to write a shell script on a linux node for the following requirement:

netstat –an|grep 1522|wc –l
the count should not be greater than 900

Can any one please help me to write the script?

Its an urgent requirement and your immediate help will be highly appreciated and helpful.

Regards,
Sudipta
12 REPLIES 12
lauri_r
Honored Contributor

Re: Help required in shell script

What exactly that script should do with results? You have a command, that gives somekind of number as a result, what you want to do with it? Whats your aim?

And you are lousy pointgiver, maybe by trying to appreciate others time you could get better answers?
Mampi_Mumbai
Regular Advisor

Re: Help required in shell script

Lauri,

I always assign the appropriate points to people whose suggestions genuinely help me to resolve my issues.

Sorry, You haven't done the same and hence haven't received points.

My aim is to monitor and get alerts as and when the output of the mentioned command exceeds 900. For creating a policy i need to write the script on the managed node

Regards,
Sudipta
Jai Ganesh
Trusted Contributor
Solution

Re: Help required in shell script

Hi,

Please copy the below script and save it as count.sh

count=`netstat â an|grep 1522|wc â l`
if [ $count > 900 ]; then
/opt/OV/bin/opcmsg a=Script o=count.sh msg_grp=OS severity=Critical msg_text="Count Exceeded"
fi

and execute chmod 755 count.sh in the directory where you saved the script.

And create a message template to capture the alert and schedule the script using schedule template or cron.

Jai.
Jai Ganesh
Trusted Contributor

Re: Help required in shell script

remove the junk in my previous post

its

count=`netstat -an | grep 1522 | wc -l`

Jai.
Mampi_Mumbai
Regular Advisor

Re: Help required in shell script

Thanks Jai...

Assigned 10 points to you.
Jai Ganesh
Trusted Contributor

Re: Help required in shell script

Thanks Sudipta.
Mampi_Mumbai
Regular Advisor

Re: Help required in shell script

Hi,

But I am getting false alerts ..even if the count is not 900, i am getting an alert saying its greater than 900.

I have deployed a scheduled task policy.

Can you please help
Peter Marko
Honored Contributor

Re: Help required in shell script

first regarding your generosity with points - it's not about giving points to those who solve your homeworks, it's about showing effort ;)

second - your request is unrelated to OM so ...

third - try "man sh" or "man bash" and find there how integers should be compared algebraically
Jai Ganesh
Trusted Contributor

Re: Help required in shell script

Hi,

Please copy the below script

count=`netstat -an|grep 1522|wc -l`
if test $count -gt 900
then
echo "Count Exceeded"
fi