0

As part of smooth functioning on my application I want to check a count of a particular process and send a email to multiple people if it exceeds certain limit.I have written script for counting process but I dont know for the email part.

Code for processes count

#!/bin/sh
NOP=`ps -ef | grep -I nagios.cfg | grep -v grep |wc -l`
if [ $NOP -gt 2 ]
then
(
echo "More parent processes are running on the server"
)
fi
1

mail command is pretty simple:

echo "More parent processes are running on the server" | mail -s "subject" user@example.org user2@example.org

And your script can be optimized to one line:

[ "$(pgrep -c nagios.cfg)" -gt 2 ] && echo "More parent processes are running on the server" | mail -s "subject" user@example.org user2@example.org
1

how about simple mail command in the end.

it sends email to abc@xyz.com

#!/bin/sh
NOP=`ps -ef | grep -I nagios.cfg | grep -v grep |wc -l`
if [ $NOP -gt 2 ]
then
(
echo "More parent processes are running on the server" | mail -s "More parent processes are running on the server"  abc@xyz.com
)
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.