Adam Hall
Adam Hall

Reputation: 1

Bash outputting kill usage

I have a bash script as follows:

if [[ "$1" == "stop"  ]]; then

 echo "[$(date +'%d/%m/%Y %H:%M:%S:%s')]: Killing all active watchers" >> $LOG

 kill -9 $(ps -ef | grep "processname1" | grep -v "grep" | grep -v "$$" | awk 
 '{print $2}' | xargs)

 echo "[$(date +'%d/%m/%Y %H:%M:%S:%s')]: Killing all current processname2 
 processes" >> $LOG

 kill -9 $(ps -ef | grep "processname2" | grep -v "grep" | awk '{print $2}' | 
 xargs)

 exit 0

when i run 'x service stop', the following is outputted:

kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill 
-l [sigspec]
Killed

How do i stop the kill usage being displayed? It is successfully killing the process, however the fact that the usage is displayed is causing AWS CodeDeploy to fail.

Thanks!

Upvotes: 0

Views: 221

Answers (1)

glenn jackman
glenn jackman

Reputation: 247062

Adam, please note that this is really just a comment with formatting. Don't take this as a real answer to your question. Please focus on the constructive comments to your question.

In my mis-spent youth, I wrote this bash function to do the ps -ef | grep .... madness:

# ps-grep
psg() { 
    local -a patterns=()
    (( $# == 0 )) && set -- $USER
    for arg do
        patterns+=("-e" "[${arg:0:1}]${arg:1}")
    done
    ps -ef | grep "${patterns[@]}"
}

using the knowledge that the pattern [p]rocessname will not match the string [p]rocessname

Upvotes: 1

Related Questions