-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--HG-- extra : convert_revision : svn%3Aa4405340-9a3f-0410-a3d8-31b31f83d5c0/trunk%402
- Loading branch information
boards
committed
Nov 23, 2007
1 parent
641e1af
commit 1411895
Showing
7 changed files
with
887 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
1.0.3: | ||
* Updated license to GPLv3. | ||
* New run-time option, -p, for Perl regular expressions. | ||
* New man page! | ||
* Updated install script to use bash as well as to install the man page. | ||
|
||
1.0.2: | ||
* Since Ubuntu changed /bin/sh to dash instead of bash, I've realised that | ||
this does indeed use bashisms. Thereform, I have changed the shell to use | ||
/usr/bin/env bash instead. | ||
|
||
1.0.1: | ||
* Doesn't show itself in process list. | ||
|
||
1.0: | ||
* Initial release. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
To install, just execute ./install.sh. If you wish to install psgrep somewhere | ||
other than /usr/local/bin, set the $PREFIX variable like so: | ||
PREFIX=/usr sudo ./install.sh | ||
The default $PREFIX is /usr/local | ||
|
||
If you, for example, install psgrep to your home directory, don't forget to set | ||
your PATH to include "~/bin" as well as your MANPATH (or ~/.manpath) to include | ||
"~/share/man". |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Put this into some sort of version control (e.g., git, svn, bazaar-ng). | ||
* Add more grep options. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
usage() | ||
{ | ||
echo "Usage: $0 | ||
To change the prefix, set the PREFIX variable before running; e.g. | ||
PREFIX=/usr $0 | ||
The default PREFIX is /usr/local" | ||
exit 1 | ||
} | ||
|
||
[ $# -ge 1 ] && usage | ||
|
||
install psgrep ${PREFIX:-/usr/local}/bin/psgrep | ||
install psgrep.1 ${PREFIX:-/usr/local}/share/man/man1/psgrep.1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env bash | ||
# © 2006-2007 Matt Sicker | ||
# This program is Free Software; you may copy, modify, and distribute it under | ||
# the terms of the GNU General Public License version 3, or (at your option) | ||
# any later version published by the Free Software Foundation. | ||
# If you did not receive a copy of the GPL with this distribution, you can | ||
# download the latest version at <http://www.gnu.org/licenses/gpl.txt> or write | ||
# to: | ||
# Free Software Foundation, Inc., | ||
# 51 Franklin St - Fifth Floor, | ||
# Boston, MA 02110-1301 USA | ||
# | ||
# BLAH BLAH WARRANTY: | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
PS_CMD="$(which ps)" | ||
PS_OPTS="aux" | ||
GREP_CMD="$(which grep)" | ||
GREP_OPTS="" | ||
|
||
PSGREP_VERSION="1.0.3" | ||
|
||
usage() | ||
{ | ||
echo "Usage: $0 [options] <search terms> | ||
Options: | ||
-b Search using BSD's ps format (aux) [default] | ||
-l Search using Linux's ps format (-ef) | ||
-s Search using simplified format (PID, user, command) | ||
-o <opts> Search using custom ps output format | ||
-e Use extended regexps (egrep) | ||
-p Use perl regexps (grep -P) | ||
-h View this message | ||
-v View version information" | ||
exit 1 | ||
} | ||
|
||
version_info() | ||
{ | ||
echo "psgrep version ${PSGREP_VERSION} | ||
© 2006-2007 Matt Sicker | ||
This program comes with ABSOLUTELY NO WARRANTY; for details, see the included | ||
COPYING file. This is free software, and you are welcome to redistribute it | ||
under certain conditions; see the included COPYING file for details. In short, | ||
you may copy, modify, and re/distribute it under the terms of the GNU General | ||
Public License version 3, or (at your option) any later version." | ||
exit 2 | ||
} | ||
|
||
[ $# -lt 1 ] && usage | ||
|
||
while getopts "blso:ephv" opt; do | ||
case $opt in | ||
h) usage;; | ||
v) version_info;; | ||
b) PS_OPTS="aux";; | ||
l) PS_OPTS="-ef";; | ||
s) PS_OPTS="-eo pid,euser,comm";; | ||
o) PS_OPTS="-eo $OPTARG";; | ||
e) GREP_CMD="${GREP_CMD} -E";; | ||
p) GREP_CMD="${GREP_CMD} -P";; | ||
esac | ||
done | ||
|
||
# now the actual execution | ||
# HOLY SHIT did it take forever to figure out how to use the rest of the command | ||
$PS_CMD $PS_OPTS | $GREP_CMD ${@:$OPTIND} | $GREP_CMD -v "$GREP_CMD" | $GREP_CMD -v "$0" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
.\" vim:syn=groff: | ||
.\" Man page for psgrep | ||
.TH PSGREP 1 "2007-06-30" "" "psgrep Manual" | ||
. | ||
.SH NAME | ||
psgrep \- search process list using the power of grep | ||
. | ||
.SH SYNOPSIS | ||
psgrep [options] \fIPATTERN\fR | ||
. | ||
.SH DESCRIPTION | ||
.PP | ||
psgrep is a small Bash shell script that searches the process list (as obtained | ||
by | ||
.BR ps (1) | ||
) using the awesome utility | ||
.BR grep (1) | ||
for its power. It is more useful than | ||
.BR pgrep (1) | ||
because not only can it search the process list and return a PID, it can give | ||
more useful information such as its UID, GID, memory/CPU usage, niceness, and | ||
anything else supported by ps. It is also more useful than using something like | ||
.RS | ||
ps aux | grep \fIPATTERN\fR | ||
.RE | ||
because it also prevents the matching of the ps or grep processes used for | ||
searching the list. In fact, the main reasoning behind the original writing | ||
of this script was entirely due to this annoyance with the given method. | ||
. | ||
.SH OPTIONS | ||
.TP | ||
.B -b | ||
Search the process list using BSD's \*(lqps aux\*(rq format (default). | ||
. | ||
.TP | ||
.B -l | ||
Search the process list using Linux's \*(lqps -ef\*(rq format. | ||
. | ||
.TP | ||
.B -s | ||
Search the process list using a simplified format: \*(lq\fIPID, user, command\fR\*(rq. | ||
. | ||
.TP | ||
.BI -o " OUTFORMAT" | ||
Search using a custom ps output format as specified by \fIOUTFORMAT\fR. See | ||
.BR ps (1) | ||
and its \fB-o\fR option as well as its \fBSTANDARD FORMAT SPECIFIERS\fR section | ||
for more information on how to use this. | ||
.\" XXX: should we just yank that section from ps(1) and put it here? | ||
. | ||
.TP | ||
.B -e | ||
Search using extended regular expressions (i.e., using \*(lqegrep\*(rq or | ||
\*(lqgrep -E\*(rq). | ||
. | ||
.TP | ||
.B -p | ||
Search using Perl regular expressions (i.e., using \*(lqgrep -P\*(rq). | ||
. | ||
.TP | ||
.B -h | ||
Display a brief usage message, and exit with a status of 1. | ||
. | ||
.TP | ||
.B -v | ||
Display version and licensing info, and exit with a status of 2. | ||
. | ||
.SH BUGS | ||
No known bugs, but if you find any, please email them to <boards@gmail.com>. | ||
. | ||
.SH AUTHORS | ||
psgrep was written by Matt Sicker with help from your local manpages. | ||
. | ||
.SH COPYRIGHT | ||
.PP | ||
psgrep is Copyright (C) 2006-2007 Matt Sicker. | ||
.PP | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
.PP | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
.PP | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
.PP | ||
If you wish to make use of this program with a license other than the GPL, | ||
please contact the author at <boards@gmail.com> with a request (and a | ||
reason of course!). | ||
. | ||
.SH SEE ALSO | ||
.BR ps (1) , | ||
.BR grep (1) , | ||
.BR pgrep (1) |