Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to kill processes, restart them and check if restarted successf

Status
Not open for further replies.

GABRIEL123

Technical User
Jan 28, 2003
2
GB
Hello all, I was wondering if anyone can help me with the above. I need to write an unix script which does the following :

1.) greps for processes wanting to kill
2.) kills them
3.) appends killed processes to a log
4.) restarts them
5.) appends restarted processes to a log

Any help would be much appreciated . . . .

Thanks . . . .
 
#!/usr/bin/ksh -p

PF() {
if [ $? -eq 0 ]
then
echo "Restarted Process: ${RAP}."
else
echo "Failed to restart Process: ${RAP}."
fi
}

for RAP in SOMEONE WHO WHY IS THIS #RAP=Run away process
do
RAPPID=`ps -ef|grep ${RAP}|awk '{print $2}'`
if [ ${RAPPID} != "" ]
then
kill -9 ${RAPPID}
echo "Killed Process: ${RAP}."
fi
if [ "${RAP}" == "SOMEONE" ]
then
sh /etc/rc.d/SOMEONE start # Example
PF
elif [ etc,etc ]
then
fi
done


That should work or at least get you started.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top