0

I am using the following command to kill my servers at the moment and want to combine them into one.

1- ps aux | grep 'python manage.py runserver' 
   sudo kill -9 $PID
2- ps aux | grep 'python -m SimpleHTTPServer'
   sudo kill -9 $PID
3- ps aux | grep 'aptly api server'
   sudo kill -9 $PID 

Is there a way to kill all the three processes using a single command? or atleast combine them.

EDIT: I am trying the below command but it is just print out single PID number. enter image description here

python
  • 4,403
  • 13
  • 56
  • 103

1 Answers1

2
ps aux | egrep -i 'python manage.py runserver|aptly api serve|python -m SimpleHTTPServer' | awk '{print $2}' | xargs kill -9
python
  • 4,403
  • 13
  • 56
  • 103
Alex Hall
  • 34,833
  • 5
  • 57
  • 89
  • Why it is only printing out one a single PID ? `rakesh@r:~$ ps aux | grep 'python manage.py runserver | python -m SimpleHTTPServer | aptly api server' | awk '{print $2}' 3698` – python Oct 12 '15 at 02:01
  • Possibly because I inserted spaces in the regex where I shouldn't have. Try it now. – Alex Hall Oct 12 '15 at 02:03
  • Nothing cnanges. `rakesh@r:~$ ps aux | grep 'python manage.py runserver|python -m SimpleHTTPServer|aptly api server' | awk '{print $2}' 3775` – python Oct 12 '15 at 02:05
  • Ah, I think it was also just picking up the `grep` process itself and not working because `|` by default isn't recognized by `grep` as a regex special char. Try now. – Alex Hall Oct 12 '15 at 02:08
  • What does `ps aux | grep 'python\|aptly'` get you? What about `ps aux | egrep 'python|aptly'`? – Alex Hall Oct 12 '15 at 02:15
  • `ps aux | grep 'python\|aptly` --> `rakesh@r:~$ ps aux | grep 'python manage.py\|aplty api serve' rakesh 4053 0.3 0.7 75088 28476 pts/4 S+ 22:17 0:00 python manage.py runserver 0.0.0.0:8000 rakesh 4067 2.0 0.8 151856 30628 pts/4 Sl+ 22:17 0:01 /opt/moorgate/bin/python manage.py runserver 0.0.0.0:8000 rakesh 4086 0.0 0.0 15944 2232 pts/11 S+ 22:18 0:00 grep --color=auto python manage.py\|aplty api serve` – python Oct 12 '15 at 02:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91993/discussion-between-alex-hall-and-rakesh-ranjan-sukla). – Alex Hall Oct 12 '15 at 02:22
  • `ps aux | egrep -i 'python manage.py runserver|aptly api serve|python -m SimpleHTTPServer'` this one gives out all the server name – python Oct 12 '15 at 02:24