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,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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
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
ASKER
Excellent answer.
Also, why not tmpfile=$(mktemp)