Skip to content

Commit

Permalink
Support differential record output
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Aug 4, 2018
1 parent 615c51b commit 5bf4542
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pmonitor.1
Expand Up @@ -22,6 +22,7 @@ pmonitor \- monitor a job's progress
\fB\-f\fP \fIfile\fP |
\fB\-p\fP \fIpid\fP
[\fB-i\fP \fIinterval\fP]
[\fB-d\fP]
[\fB-u\fP]
.SH DESCRIPTION
The \fIpmonitor\fP command will display the progress of a process
Expand All @@ -45,6 +46,11 @@ argument starts with a \fC/\fP.
See the documentation of the \fIlsof\fP(1) \fB\-c\fP option regarding
the rules and flags associated with the use of regular expressions.

.TP
\fB\-d\fP, \fB\-\-diff\fP
In repeated output mode,
output only records that differ from one iteration to the next.

.TP
\fB\-f\fP, \fB\-\-file\fP=\fIFILE\fP
Monitor a process's progress through its processing of the specified file.
Expand Down
19 changes: 15 additions & 4 deletions pmonitor.sh
Expand Up @@ -88,7 +88,10 @@ display()
eta_h = t
eta = sprintf(" ETA %d:%02d:%02d", eta_h, eta_m, eta_s)
}
print fname, offset / len * 100 "%" eta
out = fname "\t" offset / len * 100 "%" eta
if (!'$ONLYDIFF' || !seen[out])
print out
seen[out] = 1
}
}
'
Expand All @@ -100,8 +103,9 @@ usage()
cat <<\EOF 1>&2
Usage:
pmonitor [-c command] [-f file] [-i interval] [-p pid]
pmonitor [-c command] [-d] [-f file] [-i interval] [-p pid]
-c, --command=COMMAND Monitor the progress of the specified running command
-d, --diff During continuous display show only records that differ
-f, --file=FILE Monitor the progress of commands processing the
specified file
-h, --help Display this message and exit
Expand All @@ -123,14 +127,14 @@ EOF
# We need TEMP as the `eval set --' would nuke the return value of getopt.

# Allowed short options
SHORTOPT=c:,f:,h,i:,p:,u
SHORTOPT=c:,d,f:,h,i:,p:,u

if getopt -l >/dev/null 2>&1 ; then
# Simple (e.g. FreeBSD) getopt
TEMP=$(getopt $SHORTOPT "$@")
else
# Long options supported
TEMP=$(getopt -o $SHORTOPT --long command:,file:,help,interval:,pid:,update -n 'pmonitor' -- "$@")
TEMP=$(getopt -o $SHORTOPT --long command:,diff,file:,help,interval:,pid:,update -n 'pmonitor' -- "$@")
fi

if [ $? != 0 ] ; then
Expand All @@ -141,6 +145,8 @@ fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

ONLYDIFF=0

while : ; do
case "$1" in
-c|--command)
Expand All @@ -149,6 +155,10 @@ while : ; do
OPT2="$2"
shift 2
;;
-d|--diff)
ONLYDIFF=1
shift
;;
-f|--file)
test -z "$OPT1" || usage
OPT1=--
Expand Down Expand Up @@ -197,6 +207,7 @@ if [ "$INTERVAL" ] ; then
sleep $INTERVAL
done
else
ONLYDIFF=0
opt_lsof
fi |
display

0 comments on commit 5bf4542

Please sign in to comment.