#!/bin/bash
#
# send_remote_values_file
#
# Sendet alle Teststeps eines Remote Rechners and ULS
#
# Aufruf:
#
# send_remote_values_file <IP-Adresse> <Port> <User> <Passwort> [<Proxy:Port>]
#                         [<u2w-Proxy>]
#
###################################################################################
#
PATH=/usr/bin:/srv/uls/wwwbin:/usr/local/uls/wwwbin:/usr/local/bin:$PATH
export PATH
#
if [ -f /etc/uls/uls.conf ]
 then
  . /etc/uls/uls.conf
elif [ -f /etc/uls.conf ]
 then
  . /etc/uls.conf
fi
#
if [ -z "$ULSHOSTNAME" ]
 then
  ULSHOSTNAME=`hostname`
fi
#
if [ "$ULSSERVER" = "STORE" ]
 then
  echo "Lokal wird nur gespeichert, das macht keinen Sinn!"
###  exit 2
fi
#
if [ -z "$ULSSERVER" ]
 then
  ULSSERVER=localhost:11975
  SFLAG=""
fi
#
#
if [ $# -lt 4 ]
 then
  echo "usage: $0 <IP-Adresse> <Port> <User> <Passwort> [<Proxy:Port>] [<u2w-Proxy>]"
  exit 1
fi
#
if [ -z "$5" ]
 then
  P=""
else
  P="-P $5"
fi
if [ -z "$6" ]
 then
  U=""
  H="$1:$2"
else
  U="?host=$1:$2&user=$3&pwd=$4"
  H="$6"
fi
#
LOKALE_STORE_DATEI=/dev/shm/remote_value_store$$
#
if STATUS=`httpget -u logging -p lgput -s $ULSSERVER get_status.s2w?hostname=$ULSHOSTNAME`
 then
  if [ "$STATUS" = "OK" ]
   then
    if httpget -s -u "$3" -p "$4" $P "$H" "/get_clear_uls.s3w$U" | head -c 30m >$LOKALE_STORE_DATEI
     then
      RET=`cat $LOKALE_STORE_DATEI | httpget -c -i -u logging -p lgput -s $ULSSERVER | tail -n 1`
      if [ "$RET" != "OK" ]
       then
        echo "Error: $RET"
      fi
    fi
    rm -f $LOKALE_STORE_DATEI
  fi
fi
