so i was doing some misc work on one of my machines the other day and as i was working i kept having this service restarting even though i kind of needed it on but at the time i needed it off.

so i wrote this stupid little find, message and kill script to cron out the kills.

this script assumes you have a valid mailer installed (i use mailx):

#!/bin/bash

ADMIN=me@email.com
TEMP_FILE=/tmp/proc_kill.tmp
TOP=/usr/bin/top

# this case finds and messages admin up top
if [ -f ${TEMP_FILE} ]; then
        rm -rfd ${TEMP_FILE} && touch ${TEMP_FILE}
fi

# change <replace me> to process name you need killed off
${TOP} -b -n 1 | egrep <replace me> ${TEMP_FILE}

if [ -s ${TEMP_FILE} ]; then
        DEAD_PID=`cat ${TEMP_FILE} | awk '{print $1}'`
        printf "pid ${DEAD_PID} being killed." | mailx -s "pid being killed" $ADMIN
        kill -9 ${DEAD_PID}
fi

it serves a purpose…..sort of