19 echo "Usage: $0 [-h|--help] [-t|--timeout <value>] [-f|--file <file>] [-p|--ping] [operation] "
21 echo " -h|--help: this usage help."
22 echo " -t|--timeout <value>: timeout for operation in seconds."
23 echo " Defaults to $TIMEOUT__dflt seconds if not provided."
24 echo " -f|--file <file>: file with one operation per line (comments # allowed)."
25 echo " -p|--ping: Check the target process id."
26 echo " Returns 1 (dead) or 0 (alive)."
27 echo " operation: quoted operation string. Will be ignored if file"
28 echo " option is present. It is a positional argument"
29 echo " (the last one) when present."
33 echo " $0 \"test|ttps|50\""
34 echo " $0 --file myOperationsList.txt"
35 echo " $0 --timeout 10 --file ./bigList.txt"
41 timeout=$TIMEOUT__dflt
46 while [ $# -gt 0 ]; do
54 [ -z "$timeout" ] && _exit "Missing timeout value"
61 [ -z "$file" ] && _exit "Missing file"
62 [ ! -f "$file" ] && _exit "Can't found provided file '$file'."
71 first=$(echo $1 | cut -c1)
72 [ "$first" = "-" ] && _exit "Unsupported script option: $1. Type '$SCR_BN -h' (or --help) to print the available options."
80 [ -z "$is_file" -a -z "$operation" -a -z "$ping" ] && _exit "Missing operation or file with operations"
85 kill -0 $1 2>/dev/null
94 [ ! -f .pid ] && _exit "Can't found '`pwd`/.pid'.\nTry to pgrep your process name and dump pid to that file."
98 [ "$1" = "" -o "$1" = "--help" -o "$1" = "-h" ] && usage
104 [ -n "$ping" ] && exit $res
105 [ $res -ne 0 ] && _exit "Operation error: missing process with pid $PID"
112 echo $operation > sigusr2.in
118 # Detect EOF and print all except that last line:
119 count=$((10*timeout))
121 while [ $count -gt 0 ]
125 if tail -1 sigusr2.out | grep "^EOF" >/dev/null; then
133 head --lines=-1 sigusr2.out
135 _exit "Operation error: timeout expired ($timeout seconds)"
138 exception=$(grep "^Operation processed with exception: " sigusr2.out)
139 [ $? -eq 0 ] && _exit "(detected 'exception' within operation output: see 'launcher.trace')"