#!/bin/sh
# This script is for checking the status of SSHD2 Number of connections
CHKOUT="Please also Check the Number of ORPHAN / DEFUNCT Process on `hostname` :"
DFOUT=`/usr/bin/ps -eaf | grep defucnt`
SHCOUNT=`/usr/bin/pgrep sshd2|wc -l`
if [ $SHCOUNT -gt 150 ]
then
mailx -s "Warning! : `hostname` has more than $SHCOUNT SSHD2 Connections running Please Check!" [email protected] << EOF
`echo $CHKOUT`
`echo "=========================================================="`
`echo $DFOUT`
EOF
fi
=======================================
我无法获得“DFOUT”变量的输出,你们能建议正确的方法吗?
===================
Edited code that is working nice..
#!/bin/sh
# This script is for checking the status of SSHD2 Number of connections
CHKOUT="Please also Check the Number of ORPHAN / DEFUNCT Process on `hostname` :"
PS=`/usr/bin/ps -eaf | grep -v grep| grep defunct`
SHNT=`/usr/bin/pgrep ssh|wc -l`
if [ $SHNT -gt 15 ]
then
mailx -s "Warning! `hostname` has more than $SHNT SSHD2 Connections running Please Check!" [email protected] << EOF
Hi Team,
$CHKOUT
===========================================================
$PS
EOF
fi
答案1
该问题可能与以下事实有关:echo 命令应该写入,mailx STDIN
但使用内联反引号执行此操作的方式可能会出现问题。我会尝试将消息正文通过管道传输到mailx
:
...
then
SEP="============================================"
BODY="$CHKOUT\n$SEP\n$DFOUT"
echo $BODY | mailx -s "Warning! : ..."
fi