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!
Advertisement