home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # A shell script that starts up a number of programs to feed data into ProcMeter
- #
- # Written by Andrew M. Bishop
- #
- # This file Copyright 1997 Andrew M. Bishop
- # It may be distributed under the GNU Public License, version 2, or
- # any higher version. See section COPYING of the GNU Public license
- # for conditions under which this file may be redistributed.
- #
-
- # Constants
-
- lib=/usr/X11R6/lib/X11/procmeter
- dir=/tmp
-
- # Check the arguments
-
- if [ $# = 0 ]; then
- echo ''
- echo A program to start ProcMeter and a number of programs to feed data into it.
- echo ''
- echo Usage: start-procmeter \"program1 args1\" \"program2 args2\" -- procmeter-args
- echo ''
- echo Each of the programs must take as its final argument the basename to use for the
- echo definition '(.def)' and data '(.dat)' files, see the ProcMeter README for details.
- echo ''
- echo Programs that are specified are checked for in the current directory, in the
- echo library directory $lib and on the path in that order.
- echo ''
- echo In $lib are the following programs:
- cd $lib
- for f in *; do
- [ -x $f ] && echo " $f"
- done
- echo ''
- exit 0
- fi
-
- # Variables
-
- pids=
- data=
- files=
- num=0
- args=
-
- # Start all of the programs
-
- while [ ! $# = 0 ]; do
-
- if [ "$1" = -- ]; then
- num=-1
- elif [ $num -ge 0 ]; then
- num=`expr 1 + $num`
- file=$dir/.procmeter-$$-$num
- data="$data -data $file.dat"
- files="$files $file.def $file.dat"
-
- rm -f $file.def $file.dat
-
- prog=`echo $1 | cut -d' ' -f1`
-
- if [ -x ./$prog ] ; then
- prefix=./
- elif [ -x $prog ] ; then
- prefix=
- elif [ -x $lib/$prog ] ; then
- prefix=$lib/
- elif [ `basename $prog` = $prog ] && hash -- $prog 2> /dev/null; then
- prefix=
- else
- echo Cannot find $prog here, on the path, or in the library $lib.
- kill $pids
- rm -f $files
- exit 1
- fi
-
- echo Starting $prefix$1
-
- $prefix$1 $file &
-
- pids="$pids $!"
- else
- args="$args $1"
- fi
-
- shift
-
- done
-
- [ "$pids" ] && sleep 1
-
- # Start ProcMeter
-
- trap "echo Exiting" SIGINT
- trap "echo Exiting" SIGTERM
-
- echo Starting ProcMeter
- procmeter $args $data
-
- # Wait until ProcMeter is killed or the script is interrupted and tidy up
-
- kill $pids
-
- rm -f $files
-