#!/bin/bash

###
### Service: Check Domain: 2minutenagios.com
### Sample: $USER1$/check_domain.php -w 15 -c 5 $ARG8$ -d $$($USER1$/EWG_getvalues -s "$SERVICEDESC$")
### Returns: CheckDomain:2minutenagios.com
### of, with -l
### Sample: $USER1$/check_domain.php -w 15 -c 5 $ARG8$ -d $$($USER1$/EWG_getvalues -l -s "$SERVICEDESC$")
### Returns: 2minutenagios.com
###

default=""
lookFor="service"
useLast=""
service=""
output=""
verbose="false"

while [ -n "$1" ]; do
  case "$1" in
    -s) service="$2"; shift 1;;
    -e) lookFor="$2"; shift 1;;
    -l) useLast="true"; shift 1;;
    -v) verbose="true"; shift 1;;
    *) default="$1"; shift 1;;
  esac
done

[ -z "$service" ] && exit 0

do_service() {
  $verbose && echo "output=$output"
  [ -n "$useLast" ] && service=$(echo "$service" | awk '{print $NF}')
  output="$service"
  $verbose && echo "service=$service"
  output=$(echo "$output" | tr -d " ")
}

case "$lookFor" in
  sv|svc|service) do_service;;
  *) output="";;
esac

echo "$output"
