#!/bin/bash

# ********************************************************************
#
#  This program is free software; you can redistribute it and/or modify it 
#  under the terms of the GNU General Public License as published by the Free 
#  Software Foundation; either version 2 of the License, or (at your option) 
#  any later version.
#  
#  This program is distributed in the hope that it will be useful, but WITHOUT 
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
#  more details.
#  
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 
#  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#  
#  The full GNU General Public License is included in this distribution in the
#  file called LICENSE.
#  
#*******************************************************************************
# 
#
# receive parameters:
# $1 (store|receive)
# $2 IP
# $3 ID
# $4 Flagge
#
# Returns:
# 0: remote malfunction, service not up, answer garbled, other remote failures
# 1: service up, no flag  (not used for 'store')
# 2: success
# 3: internal error/local failure

#set -x

#echo "Executed $(date) $1 for IP $2." >> /tmp/invokation.debug

if [ $# -lt 4 ] ; then
	echo "script called with too less parameters"
	exit 3
fi

if [ "$1" == "store" ] ; then
        #postfix="%\ packet loss"    

 	ping -nq -c 4 $2
 	result=$?
 	
 	if [[ $result = "0" ]]; then
 	    exit 2
 	else 
 	    exit 0
 	fi    
 	
elif [ "$1" == "retrieve" ] ; then
 	ping -nq -c 4 $2
 	result=$?
 	
 	if [[ $result = "0" ]]; then
 	    exit 2
 	else 
 	    exit 0
 	fi    
else
	echo "script called with unknown operation"
        exit 3
fi


