JustMe
JustMe

Reputation: 51

Don't kill created processes, which created by ps - linux

give some advice, please.

I am trying to kill processes remotely (ssh to hostname), find some processes and kill them. But I have a condition: Do not kill java process, sshd and gnome.

Here is example (I just do echo except kill):

#/bin/sh -x.
HOSTFILE=$1
vars=`cat $HOSTFILE`
for i in $vars; do
 ssh  "$i" /bin/bash <<'EOF'
  echo $(hostname)
  ps aux | grep -e '^sys_ctl'| grep -v "java" | grep -v "sshd" | \
  grep -v "gnome" | awk '{print $2$11}'|  for i in `xargs echo`; do  echo $i; done;
EOF
done

The result is:

host1:
21707/bin/bash
21717ps
21718grep
21722awk
21723/bin/bash
21724xargs
host2:
15241/bin/bash
15251ps
15252grep
15256awk
15257/bin/bash
15258xargs
89740-bash
98467sleep
98469sleep
98471sleep
98472sleep
98474sleep
98475sleep

I want to kill (output), only sleep processes, not grep,awk,bash,xargs,ps Can you suggest something elegant?

Upvotes: 0

Views: 129

Answers (1)

nullPointer
nullPointer

Reputation: 4574

why not just : kill $(pgrep -f sleep) or : pkill -f sleep

Upvotes: 2

Related Questions