killing multiple processes
I have several scripts running as cron jobs. For some reason, the scripts are not working (that's another issue for later) and they are leaving hundreds of hung processes. I'm trying to kill them as a group by using the following command.
Code:
kill `ps aux | grep rduser | grep scale | awk '{print $2}'` Code:
rduser 2767 0.0 0.0 3340 548 ? SN Jun02 0:00 lame -m s -a --scale 20 --quiet --nohist /mnt/TV3/010003_022.wav /var/snd/ftp/FNC/FNC_Sun Code:
$ kill `ps aux | grep rduser | grep scale | awk '{print $2}'` Any ideas on what I am doing wrong would be appreciated. Michael |
The
Code:
grep scale |
I think I understand that. So what do I do to fix it?
|
Add a
Code:
grep -v grep |
That was the secret. Works fine now. Thanks.
|
Argh. 'pgrep' and 'pkill' were meant to combat that. See 'man pkill', the "-f" switch. Example:
Code:
]$ \ps --no-headers -C lame -o args |
Note that you can get a similar 'not found' effect if you use a simple kill on progs that fork.
If the child dies, the parent may also exit before your kill cmd gets to it. |
Since you are already using awk, get it to do the kill
Code:
ps aux | awk '!/awk/ && /^rduser.*--scale/{system("kill "$2)}' |
All times are GMT -5. The time now is 10:15 PM. |