Link to home
Start Free TrialLog in
Avatar of sam15
sam15

asked on

Shell script to count lines

How can i write a shell script on RHEL 7.4 that does that counts number of line in netstat and if total lines exceeds 200 lines
send an email alert to "joe.blow@xyz.com" with the number of lines and actual listing.

netstat|wc

I want to schedule this script to run every 5 minutes via cron to monitor a connections performance issue.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Abhimanyu Suri
Abhimanyu Suri
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Should append rm ${tmpfile} to the above script.
Also, why not tmpfile=$(mktemp)
Avatar of sam15
sam15

ASKER

Excellent script. works like a charm!

netstat list has two sections: active Internet connections and active unix domain sockets.

Is there a way to remove the  second list from the count and email?

Also, if I want to add second email, do you just separate them by semicolon?
For mailx just add recipient separated by space

For sections, you can use something like below

cat ${tmpfile}|grep -in ^active
1:Active Internet connections
147:Active Multipath Internet connections
149:Active LOCAL (UNIX) domain sockets
435:Active kernel event sockets
460:Active kernel control sockets

Open in new window

Avatar of sam15

ASKER

Excellent answer.