+usage() {
+ echo
+ echo "Usage: $0 [-h|--help] [-t|--timeout <value>] [-f|--file <file>] [-p|--ping] [operation] "
+ echo
+ echo " -h|--help: this usage help."
+ echo " -t|--timeout <value>: timeout for operation in seconds."
+ echo " Defaults to $TIMEOUT__dflt seconds if not provided."
+ echo " -f|--file <file>: file with one operation per line (comments # allowed)."
+ echo " -p|--ping: Check the target process id."
+ echo " Returns 1 (dead) or 0 (alive)."
+ echo " operation: quoted operation string. Will be ignored if file"
+ echo " option is present. It is a positional argument"
+ echo " (the last one) when present."
+ 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
+ file=
+ operation=
+ ping=
+
+ 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
+ file="$2"
+ [ -z "$file" ] && _exit "Missing file"
+ [ ! -f "$file" ] && _exit "Can't found provided file '$file'."
+ shift
+ ;;
+
+ -p|--ping)
+ ping=yes
+ ;;
+
+ *)
+ first=$(echo $1 | cut -c1)
+ [ "$first" = "-" ] && _exit "Unsupported script option: $1. Type '$SCR_BN -h' (or --help) to print the available options."
+ operation="$@"
+ break
+ ;;
+ esac
+ shift
+ done
+
+ [ -z "$is_file" -a -z "$operation" -a -z "$ping" ] && _exit "Missing operation or file with operations"
+}
+
+# $1: pid to check
+check_pid() {
+ kill -0 $1 2>/dev/null
+ return $?
+}
+