Optimize clone procedure
[anna.git] / example / diameter / launcher / resources / scripts / operation_signal.sh
index 8c9ce85..85b3111 100755 (executable)
@@ -17,11 +17,20 @@ cd `dirname $0`
 PID=`cat .pid`
 
 # Send operation:
-[ "$1" = "" ] && _exit "Usage: $0 <operation string>; i.e.: $0 help"
-echo $1 > sigusr2.tasks.input
-kill -s SIGUSR2 $PID
+[ "$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"
+FILE=
+[ "$1" = "-f" ] && FILE=$2
 
-#echo "You could see results on '`pwd`/sigusr2.tasks.output' file."
-cat `pwd`/sigusr2.tasks.output 2>/dev/null
-echo
+if [ -z "$FILE" ]
+then
+  echo $1 > sigusr2.in
+else
+  [ ! -f "$FILE" ] && _exit "Can't found provided file '$FILE'."
+  grep -v "^#" $FILE | sed '/^[ \t]*$/d' > sigusr2.in
+fi
+0> sigusr2.out
+kill -s SIGUSR2 $PID
+# Detect EOF and print all except that last line:
+while [ -z "$(tail -1 sigusr2.out | grep ^EOF)" ]; do sleep 0.1; done
+head --lines=-1 `pwd`/sigusr2.out