#!/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