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

======================================

I am unable to get the output of "DFOUT" Variable, Can you guys suggest the correct way of doing this?

===================
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
2
  • Check your spelling; grep defucnt Aug 4, 2015 at 1:47
  • Warning! : Server1 has more than 232 SSHD2 Connections running Please Check! Why its taking wider space (double tabs liek) for "than $SHCOUNT" as we see in the above output
    – karn
    Aug 4, 2015 at 5:07

1 Answer 1

1

The issue might have to do with the fact that the echo commands should be writing to the mailx STDIN but the way you're doing it with inline backticks might be problematic. I'd try piping the body of the message to mailx instead:

...
then
    SEP="============================================"
    BODY="$CHKOUT\n$SEP\n$DFOUT"
    echo $BODY | mailx -s "Warning! : ..."
fi
1
  • this does not work.. BODY="$CHKOUT\n$SEP\n$DFOUT" echo $BODY | mailx -s "Warning! : ...
    – karn
    Aug 6, 2015 at 5:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .