aboutsummaryrefslogtreecommitdiff
path: root/tests/aux/respawn
blob: cd9687af2b3edba5904e6ece5f2992c62ef7b0c1 (plain)
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
#! /bin/sh

# usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME]
#                [-pid FILE] [-tag STRING] [-exit CODE]

append=0
unset name
time=1
tag=$0
code=0

while [ $# -ne 0 ]
do
    arg=$1
    shift
    case $arg in
	-append)
	    append=1;;
	-stderr)
	    name=${1:?missing argument for -stderr}
	    shift
	    if [ $append -eq 1 ]; then
		exec 2>>$name
		append=0
	    else
		exec 2>$name
	    fi;;
        -stdout)
	    name=${1:?missing argument for -stdout}
	    shift
	    if [ $append -eq 1 ]; then
		exec >>$name
		append=0
	    else
		exec >$name
	    fi;;
	-sleep)
	    time=${1:?missing argument for -sleep}
	    shift;;
	-pid)
	    name=${1:?missing argument for -pid}
	    shift
	    if [ $append -eq 1 ]; then
		echo $$ >>$name
		append=0
	    else
		echo $$ >$name
	    fi;;
	-tag)
	    tag=${1:?missing argument for -tag}
	    shift;;
	-exit)
	    code=${1:?missing argument for -exit}
	    shift;;	    
	*)  echo >&2 "$tag: invalid argument: $arg"
	    exit 1
    esac
done

echo "$tag: start"
sleep $time
echo "$tag: stop"
exit $code

Return to:

Send suggestions and report system problems to the System administrator.