-
-
Save aramisf/b18168c80f5114c36300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ################################################################################ | |
| ## Similar to run: ps aux | grep "RegExp" ## | |
| ## Script that receives a list o keywords and search then in "ps aux" command ## | |
| ## and returns ps's header and processes that where found with keywords. ## | |
| ## Accepts grep options, like '-c' to count number of matched processes. ## | |
| ################################################################################ | |
| options='' | |
| words='' | |
| for arg in "$@" | |
| do | |
| if [[ $arg =~ ^- ]]; then | |
| options="$options $arg" | |
| else | |
| if [ -z $words ]; then | |
| words="$arg" | |
| else | |
| words="$words|$arg" | |
| fi | |
| fi | |
| done | |
| if [ -z $options ]; then | |
| ps axw -o ppid,pid,user,%cpu,%mem,vsz,rss,wchan,nlwp,stime,etime,args | grep -v -e $0 -e $$ | egrep "(ELAPSED|$words)" --color=auto | |
| else | |
| ps axw -o ppid,pid,args | grep -v -e $0 -e $$ | egrep $options "($words)" --color=auto | |
| fi | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment