+usage() {
+ echo
+ echo "Usage: $0 [-h|--help] [-t|--timeout <value>] [-f|--file] <data>"
+ echo
+ echo " -h|--help: this usage help."
+ echo " -t|--timeout: timeout for operation in seconds."
+ echo " Defaults to 2 seconds if not provided."
+ echo
+ echo " -f|--file: the parameter 'data' will be interpreted as a file"
+ echo " with one operation per line. If missing, it will be"
+ echo " a single operation string."
+ echo
+ echo " data: operation string or file with several operations."
+ echo
+ echo " For example:"
+ echo " $0 help"
+ echo " $0 \"test|ttps|50\""
+ echo " $0 --file myOperationsList.txt"
+ echo " $0 --timeout 10 --file ./bigList.txt"
+ _exit
+}
+
+parse_arguments() {
+ is_file=
+ timeout=$TIMEOUT__dflt
+ data=
+
+ while [ $# -gt 0 ]; do
+ case $1 in
+ -h|--help)
+ usage
+ ;;
+
+ -t|--timeout)
+ timeout=$2
+ [ -z "$timeout" ] && _exit "Missing timeout value"
+ shift
+ ;;
+
+ -f|--file)
+ is_file=yes
+ data=$2
+ [ -z "$data" ] && _exit "Missing file"
+ [ ! -f "$data" ] && _exit "Can't found provided file '$data'."
+ shift
+ ;;
+
+ *)
+ first=$(echo $1 | cut -c1)
+ [ "$first" = "-" ] && _exit "Unsupported script option: $1. Type '$SCR_BN -h' (or --help) to print the available options."
+ data=$1
+ ;;
+ esac
+ shift
+ done
+
+ [ -z "$data" ] && _exit "Missing data value"
+}
+
+# $1: pid to check
+check_pid() {
+ kill -0 $1 2>/dev/null
+ [ $? -ne 0 ] && _exit "Operation error: missing process with pid $1"
+}
+