[CentOS] pup problem

MHR mhullrich at gmail.com
Wed Jun 2 17:20:46 UTC 2010


On Wed, Jun 2, 2010 at 9:40 AM, Bowie Bailey <Bowie_Bailey at buc.com> wrote:
> MHR wrote:
>> #!/bin/bash
>>
>> # A shell script to kill that annoying runaway seamonkey that won't die
>>
>> case `basename $0` in
>>         "seakill")      cmd=seamonkey;;
>>         "foxkill")      cmd=firefox;;
>>         *)                      echo "Unrecognized command."; exit 1;;
>> esac
>>
>> kill -9 `ps -ef | grep $cmd | grep -v grep | tail -1 | awk '{print $2}'`
>> ps -ef | grep $cmd | grep -v grep
>>
>> If it works, nothing is displayed.  If seamonkey/firefox is already
>> gone, it give me kill's error for not finding the process (or for a
>> missing process number because 'ps' couldn't find it, either).
>>
>
> Isn't that command line a bit complex?  Why not use ps options to get
> what you want rather than using grep, tail, and awk to pull the PID out
> of the standard output?
>
>    ps -C $cmd -o pid= | xargs kill -9
>    ps -fC $cmd
>

It's an old script I rarely use.  Yours looks better - I'm taking it.  :-)

Thanks

mhr



More information about the CentOS mailing list