summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2012-12-18 23:12:38 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2012-12-18 23:12:38 (GMT)
commit7a59fef12f5d03587ca939a90447ea7eead1d519 (patch)
treeabfae992b0de8398561329b9a22ec1e6181e7708
parent48511c5e0a133aafca893a999da6e105a5ed2673 (diff)
downloadbin_scripts-7a59fef12f5d03587ca939a90447ea7eead1d519.zip
bin_scripts-7a59fef12f5d03587ca939a90447ea7eead1d519.tar.gz
bin_scripts-7a59fef12f5d03587ca939a90447ea7eead1d519.tar.bz2
new script: pss
Like 'ps', with friendlier output and easy filtering
-rw-r--r--.gitignore1
-rw-r--r--configure.ac1
-rw-r--r--scripts/Makefile.am1
-rwxr-xr-xscripts/pss.in48
4 files changed, 51 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index c9f5aad..768e775 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ scripts/make_balloon
scripts/multijoin
scripts/nfs_iostat
scripts/ppsx
+scripts/pss
scripts/psx
scripts/rsx
scripts/sort-header
diff --git a/configure.ac b/configure.ac
index 1bcd639..a21d4fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@ AC_CONFIG_FILES( [
scripts/nfs_iostat
scripts/ppsx
scripts/psx
+ scripts/pss
scripts/rsx
scripts/sort-header
scripts/sum_file_sizes
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 0507ea8..1ab29d8 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -21,6 +21,7 @@ bin_SCRIPTS = \
multijoin \
nfs_iostat \
ppsx \
+ pss \
psx \
rsx \
sort-header \
diff --git a/scripts/pss.in b/scripts/pss.in
new file mode 100755
index 0000000..bb0a29d
--- /dev/null
+++ b/scripts/pss.in
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+if [ "$1" = "-h" -o "$1" = "--help" ]; then
+ BASE=$(basename $0)
+ echo "
+pss - Process Status (ps) with specific output
+Version: @VERSION@
+
+Copyright (C) 2012, A. Gordon ( gordon at cshl dot edu )
+License: AGPLv3+
+
+Usage:
+ $BASE
+ $BASE [TEXT]
+
+Runs 'ps ax' (with some extra formatting options), and optionally filters for
+TEXT in the output. PID, Username, CPU time, Start time, full command-line are
+printed.
+
+Example:
+ $BASE fox
+
+Will print any process that has 'fox' in its 'ps' line (e.g. username has 'fox'
+or command-line has 'fox' in it).
+
+"
+
+ exit
+fi
+
+PS_FORMAT=pid,user,state,pcpu,rsz,time,stime,cmd
+
+if [ -z "$1" ]; then
+ # No parameter: print all processes
+ ps -o $PS_FORMAT ax
+ exit
+fi
+
+TEXT=$1
+SAFE=${TEXT//[^A-Za-z0-9_]}
+
+SCRIPT_PID=$$
+
+# The two extra checks will discard the current script and the awk program.
+# not perfect, but acceptable (the 'ps' process might be printed)
+AWK_PROG="NR==1 || ( /${SAFE}/ && (\$1 != ${SCRIPT_PID}) && (\$1 != PROCINFO[\"pid\"]) )"
+
+ps -o $PS_FORMAT ax | awk -v IGNORECASE=1 "$AWK_PROG"