Shells: Search Processes


Motive: My aim is to check the process and also have the facility for search string and getting details about running services.



As I need to check it regularly, so I created a shell script for check that.

Step 1: Create a empty file named proc_search.sh and open it with a text-editor.


#touch proc_search.sh
#nano proc_search.sh


Step 2: Type the following code.


#!/bin/bash
STRING=$1
ps xauwww|grep -v "grep"|grep -v "local.bin.any" |grep -i $STRING


Save and Close it


Step 3: Give permission to execute


chmod ugo+x proc_search.sh


Step 4: Run the SCRIPT


#./proc_search.sh apache


This results me like this


root 3300 0.0 1.0 36648 9384 ? Ss 07:03 0:00 /usr/sbin/apache2 -k start
www-data 3437 0.0 0.5 36648 5244 ? S 07:03 0:00 /usr/sbin/apache2 -k start
www-data 3438 0.0 0.5 36648 5244 ? S 07:03 0:00 /usr/sbin/apache2 -k start
www-data 3439 0.0 0.5 36648 5244 ? S 07:03 0:00 /usr/sbin/apache2 -k start
www-data 3440 0.0 0.5 36648 5244 ? S 07:03 0:00 /usr/sbin/apache2 -k start
www-data 3441 0.0 0.5 36648 5244 ? S 07:03 0:00 /usr/sbin/apache2 -k start
thecoder 13678 0.0 0.1 3912 1200 pts/0 R+ 12:25 0:00 /bin/bash ./proc_search.sh apache


You can also search with partial word like fire or like fox


thecoder 3687 7.2 21.8 345920 195980 ? Sl 07:04 24:42 /usr/lib/firefox-3.0.14/firefox
thecoder 14275 0.0 0.1 3912 1204 pts/0 R+ 12:47 0:00 /bin/bash ./process_search.sh fox


Above was the result for the search for #proc_search fox

0 comments:

Post a Comment