Process killing BASH script

I enjoy the simplicity of shell scripting sometimes.  There are a million ways to do things, and this is how I’m presently shutting down something that isn’t being cooperative.

#!/bin/bash

ABC_PID=`ps | grep abc | awk '{print $1}'`
DEF_PID=`ps | grep def | awk '{print $1}'`

if [ -z $ABC_PID ] ; then
  echo "ABC PID is empty. Kill manually."
  exit
fi

if [ -z $DEF_PID ] ; then
  echo "DEF PID is empty. Kill manually."
  exit
fi

echo "ABC PID: " $ABC_PID
echo "DEF PID: " $DEF_PID

echo "Killing ABC and DEF with: kill -9" $ABC_PID $DEF_PID
kill -9 $ABC_PID $DEF_PID

exit

Out of necessity I changed the names to protect the … well, stuff.

See a way to improve that? Please share! Have a way you’d prefer to see it done? Share that too! Variety!

Advertisements

About John

I write about technology interests, cooking, and my own writing (sci-fi and fantasy... sometimes both). I try to keep things light, but sometimes I get side-tracked on an issue that I feel strongly about. No offense is meant, I'm just like any other person who feels strongly about something when I write. View all posts by John

Comments are disabled.

%d bloggers like this: