so I want a sh script to kill moni, since I always failed to kill its process with Ctl+c
so first I get the info and save it in a file
pet@girl:~$ ps aux|grep wiki >orignial.txt pet@girl:~$ cat orignial.txt pet 7560 0.0 0.5 96284 11628 pts/2 Sl+ 10:51 0:01 python ./wikiserver.py pet 9597 0.0 0.0 3336 792 pts/3 R+ 11:24 0:00 grep wiki pet@girl:~$
then I have
pet@girl:~$ awk -F" " '{print $0}' orignial.txt pet 7560 0.0 0.5 96284 11628 pts/2 Sl+ 10:51 0:01 python ./wikiserver.py pet 9597 0.0 0.0 3336 792 pts/3 R+ 11:24 0:00 grep wiki pet@girl:~$ awk -F" " '{print $1}' orignial.txt pet pet pet@girl:~$ awk -F" " '{print $2}' orignial.txt 7560 9597 pet@girl:~$ awk -F" " '{print $3}' orignial.txt 0.0 0.0 pet@girl:~$ awk -F" " '{print $4}' orignial.txt 0.5 0.0 pet@girl:~$
finally I need this
pet@girl:~$ awk -F" " '{print $2}' orignial.txt >2.txt pet@girl:~$ cat 2.txt 7560 9597 pet@girl:~$
:-) nice thing here is I use just one space for '''-F''', and everything is fine
then all I need is the first line
pet@girl:~$ awk '{if(NR**1); print $1; exit;}' 2.txt 7560 pet@girl:~$ awk '{print NR; print $1}' 2.txt 1 7560 2 9597 pet@girl:~$
so I use this
pet@girl:~$ awk '{if(NR**1); print $1; exit;}' 2.txt >3.txt pet@girl:~$ cat 3.txt 7560 pet@girl:~$
now I need to know how to pass it to '''kill -9'''
kill -9 `cat /dev/stdin`
let us name the above file "peter.sh" so we just use pipeline to read the file and send it to the stdin of peter.sh
cat 3.txt|sh peter.sh
to be handy I acutally have everything in one file
ps aux|grep wiki >orignial.txt awk -F" " '{print $2}' orignial.txt>2.txt awk '{if(NR**1); print $1; exit;}' 2.txt>3.txt kill -9 `cat 3.txt` rm -rf -.txt #rm tmp files
then put in /usr/bin/moin-kill the following content
#!/bin/sh sh /home/pet/moin-1.8.5/killmoin.sh
check what I used to kill virtualbox
$ps aux | grep virtual | awk '{print $2}' | xargs kill -9 //kill virtualbox