作为我的应用程序顺利运行的一部分,我想检查特定进程的计数,并在超过一定限制时向多个人发送电子邮件。我已经编写了用于计数进程的脚本,但我不知道电子邮件部分。
进程计数代码
#!/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
邮件命令非常简单:
echo "More parent processes are running on the server" | mail -s "subject" [email protected] [email protected]
您的脚本可以优化为一行:
[ "$(pgrep -c nagios.cfg)" -gt 2 ] && echo "More parent processes are running on the server" | mail -s "subject" [email protected] [email protected]
答案2
最后简单的邮件命令怎么样?
它发送电子邮件至[电子邮件受保护]
#!/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" [email protected]
)
fi