Pkill.sh [Shell script to kill process by name]

#!/bin/bash

if [ $1 -eq ""]; then
echo "Usage : ./pkill.sh <process name>"
else
get_proc=`ps -e -o pid,command | grep $1`
echo $get_proc > get_it
get_pid=`gawk -F" " '{ print $1 }' get_it`
kill -9 $get_pid
fi

The script is quite messy and certainly needs more improvement.

#!/bin/bash
if [ $1 -eq "" ] then
echo "Usage : ./pkill.sh <process name>"
else
for i in `ps ax | grep $1| cut -d ' ' -f 1`
do
  kill -9 $i
done
fi

or direct one liner…

killall <processname> 



I fixed this problem by using the following code:

for i in `ps ax | grep $1 | grep -v grep | sed 's/ *//' | sed 's/[^0-9].*//'`
do
  kill -9 $i
done