Fork variant for TestStep command
[anna.git] / example / diameter / launcher / resources / scripts / operation_signal.sh
1 #!/bin/bash
2
3 #############
4 # FUNCTIONS #
5 #############
6 _exit () {
7   echo -e "\n$1\n"
8   exit 1
9 }
10
11 #############
12 # EXECUTION #
13 #############
14 cd `dirname $0`
15 # Get the PID:
16 [ ! -f .pid ] && _exit "Can't found '`pwd`/.pid'.\nTry to pgrep your process name and dump pid to that file."
17 PID=`cat .pid`
18
19 # Send operation:
20 [ "$1" = "" ] && _exit "Usage: $0 [-f] <content: operation string or file (one operation per line) if '-f' provided>; i.e.: $0 help, $0 -f myOperationsList.txt"
21 FILE=
22 [ "$1" = "-f" ] && FILE=$2
23
24 if [ -z "$FILE" ]
25 then
26   echo $1 > sigusr2.in
27 else
28   [ ! -f "$FILE" ] && _exit "Can't found provided file '$FILE'."
29   grep -v "^#" $FILE | sed '/^[ \t]*$/d' > sigusr2.in
30 fi
31 0> sigusr2.out
32 kill -s SIGUSR2 $PID
33 count=0
34 while [ ! -s sigusr2.out -a $count -lt 500 ]; do sleep 0.01; count=$((count+1)); done
35 cat `pwd`/sigusr2.out
36