#! /bin/sh

# параметры:
# $1 - внешняя система
# $2 - exidr
# $3 - имя выходного файла

cmd=`basename $0`
LOG=${cmd/get_/}.log
if [ ! -f $LOG ]; then LOG= ; fi
dt=`date "+%F %T"`

if [ -z $URLHEADHOST ]; then
	REPLCTR=`head -1 /home/adis/exe/adisconf.ads | cut -s -d"/" -f2`
	REPLCTR=`echo -n $REPLCTR`
	if [ -z $REPLCTR ] || [ $REPLCTR = 0 ]; then
		URLHEADHOST=adishost
	else
		URLHEADHOST=rgnadishost
	fi
fi
wget -O $3 --timeout=5 --tries=1 "http://$URLHEADHOST/utils/get-external-data-text.php?codepage=cp866&external-system-code=$1&exidr=$2&field=tpovd" > /dev/null 2>&1
err=$?
if [ $LOG ]; then
	echo "=======" >> $LOG
	echo $1 $2 $3 >> $LOG
	iconv -c -fcp866 -tutf8 $3 >> $LOG
	echo -e "\n$dt `date +%T` err=$err">> $LOG
fi

exit 0
