blob: 8d912038ae08f6640ebea453da82c4435ac46668 (
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
64
65
66
67
68
69
70
|
#! /bin/bash
# add 2019-04-04 by Philippe DUVEAU, released under ASL 2.0
mysleep=./msleep
ACK=0
SLEEP=0
DELAY=500
NB=1
MESSAGE="program datas"
SIGNALED=0
ERR=$0.stderr
while getopts "cd:e:s:n:m:g" OPTION; do
case "${OPTION}" in
g)
SIGNALED=1
;;
c)
ACK=1
;;
d)
DELAY=${OPTARG}
;;
e)
ERR=${OPTARG}
;;
s)
SLEEP=${OPTARG}
;;
n)
NB=${OPTARG}
;;
m)
MESSAGE=${OPTARG}
;;
*)
exit 0
esac
done
trap 'echo "SIGTERM Received" >> '$ERR';echo $0" SIGTERM Received" >&2;exit 0' 15
if (( DELAY > 0 )); then $mysleep ${DELAY}; fi
if [ ${ACK} == 1 ]; then
while [ "x$order" != "xSTART" ]; do
read -r order
echo $order' Received' >> $ERR
echo $0' '$order' Received' >&2
done
while [ "x$order" != "xSTOP" ]; do
if (( NB > 0 )); then
echo ${MESSAGE}
echo "Message sent" >&2
(( NB-- ))
fi
unset order
read -r order
echo $order' Received' >> $ERR
echo $0' '$order' Received' >&2
if (( SLEEP > 0 )); then $mysleep ${SLEEP}; fi
done
else
while (( NB > 0 )); do
echo ${MESSAGE}
echo $0" Message sent" >&2
if (( SLEEP > 0 )); then $mysleep ${SLEEP}; fi
(( NB-- ))
done
if [ ${SIGNALED} == 1 ]; then
$mysleep 100000 &
wait
fi
fi
echo "Leaving improg_sender" >&2
|