Email engine cron problem.

We have an email engine in our corporation which is installed in Solaris based machine. It is currently facing delays in transactions. So a temporary work around was deployed that is a cronjob was made for restarting email engine every hour. We tested in lab system and it worked pretty okay but in production it failed. Cronjob executes every hour saying killed but actually the process for email engine do not get killed.
Following is the cron we made for the email engine killing script:

30 * * * * /opt/remedy/ar/AREmail/email_kill.sh

and script content is:

#! /usr/bin/ksh
PID= `ps -eaf | grep AREmail | grep -v grep | awk '{print $2}'` > /opt/remedy/ar/AREmail/email_kill.out 2>&1'

kill -9 "$PID"

do some logging from the process...

That is by, adding print statement for PID and check whether it gets the correct PID. And the script has the required permissions to kill that process.

1 Like

Yeah I have taken print for that and it is taking some different PID. I have given it appropriate permissions to do so.

30 * * * * /opt/remedy/ar/AREmail/email_kill.sh

I didn't get you.

First reaction is that the script is probably killing itself! The script invocation line includes the string "AREmail".
Try including:

grep -v "email_kill.sh"

Also the shebang line (1st line of the script is wrong).
should be

#!/usr/bin/ksh

It is rarely ever necessary to issue "kill -9" on a unix system. Are you sure that there is no tidier way to close the process?

Sorry I made writing error here. Now the original content is in question.
So could any one can figure out why doest it happening?

The original script contains a syntax error (a space character after PID=) and a logic error because it will kill itself because it's own command line contains the string "AREmail" ! Also I believe that the logfile redirect is in the wrong place.

Maybe try this alternative construct

#!/usr/bin/ksh
SCRIPT_NAME="`basename $0`"    # Name of this script
(
ps -eaf | grep "AREmail" | grep -v "grep" | grep -v "${SCRIPT_NAME}" | \
    awk '{print $2}' | while read PID
    do
        echo "killing ${PID}"
        # Remove echo when tested
        echo "kill -9 ${PID}"
    done
) 2>&1 >/opt/remedy/ar/AREmail/email_kill.out 

30 * * * * /opt/remedy/ar/AREmail/email_kill.sh

You can get pid with pgrep command in Solaris.

 
pgrep -f AREmail

If there are multiple AREmail process, either command may get multiple PIDs , You has to use loop to kill each one.

 
pgrep -f AREmail | xargs kill -9

or

 
pkill -9 -f ARemail
1 Like

I will try this in lab for sure :slight_smile: