#!/bin/bash

if [ -z "$1" ]
then
	echo "no base url given"
	exit 1
fi

BASEURL="$1"

cookiefilename=`mktemp /tmp/cookies.XXXXXX`

wget --no-check-certificate --keep-session-cookies --save-cookies $cookiefilename -qSO - "$BASEURL/hm/user/log?usr=admin@remote-nas.com&pass=Test5A123"
echo
output=`wget --no-check-certificate --keep-session-cookies --load-cookies $cookiefilename -qSO - "$BASEURL/hm/ld" 2>&1`
echo "$output"
echo
cat $cookiefilename | grep JSESSIONID
if `echo $output | grep "HTTP/1.1 204 No Content" > /dev/null` || `echo $output | grep "HTTP/1.1 502" > /dev/null`
then
	echo -ne '\a'
	date
	sleep 5
	echo -ne '\a'
	output=`wget --no-check-certificate --keep-session-cookies --load-cookies /tmp/cookies -qSO - "$BASEURL/hm/ld" 2>&1`
	echo "$output"
	echo
fi
rm $cookiefilename
