I would like to know what is this statement doing exactly, especially the awk part.
ps aux | grep 'sidekiq 5' | grep -v grep | awk '{ print $2; }' | xargs kill -${2:-'TERM'}I know the entire pipeline is supposed to kill sidekiq processes.
1 Answer
ps auxlists all processes.grep 'sidekiq 5'only displays those lines from the list that contain the string "sidekiq 5".grep -v grepremoves those lines that contain the string "grep". This is done so that thegrepprocess from the previous pipeline stage is filtered out.awk '{ print $2; }'prints the second field of each line. This field happens to be the process ID from theps auxoutput.xargs kill -${2:-'TERM'}takes the process IDs from the selected sidekiq processes and feeds them as arguments to akillcommand. The signal is either $2 or, if $2 is not defined, SIGTERM.