Simplify parsed variables. Improve dump configuration for test report by state type
[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 -0 $PID 2>/dev/null
33 [ $? -ne 0 ] && _exit "Operation error: missing process with pid $PID"
34 kill -s SIGUSR2 $PID
35
36 # Detect EOF and print all except that last line:
37 while [ -z "$(tail -1 sigusr2.out | grep ^EOF)" ]; do sleep 0.1; done
38 head --lines=-1 sigusr2.out
39
40 exception=$(grep exception sigusr2.out)
41 [ $? -eq 0 ] && _exit "(detected 'exception' within operation output)"
42 exit 0