File: start-procmeter

package info (click to toggle)
procmeter 2.5.1-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 260 kB
  • ctags: 197
  • sloc: ansic: 2,006; sh: 206; perl: 140; makefile: 106
file content (107 lines) | stat: -rwxr-xr-x 2,387 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/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=./contrib
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