#!/bin/ksh
# ce programme est cense etre lance par le programme multi_remote.sh
#
# codes retour:
# RVAL - 150  -  I didn't received the server name
# RVAL - 200  -  you must modify the nagios downtime end time
# RVAL - 170  -  the first disk sync is failed
# RVAL - 172  -  the second disk sync is failed
# RVAL - 212  -  ping HS

[ -z "$ARGUMENT_TO_WORK" ] && {
	echo "ERROR : the ARGUMENT_TO_WORK variable is not set"
	exit 150
}

/usr/sbin/ping $ARGUMENT_TO_WORK 2 >/dev/null 2>&1
if [ "$?" = "0" ]
	then
		/usr/bin/ssh -q -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -n ${ARGUMENT_TO_WORK} "PATH=\$PATH:/bin:/sbin:/usr/bin:/usr/sbin
				export PATH
				case \`uname -s\`
				in
					SunOS)	eeprom \"auto-boot?\"=true || exit 4
								sync || exit 170
								sync || exit 172
								init 5 2>&1 || exit 3 ;;
					Linux)	shutdown -h now 2>&1 || exit 3 ;;
					HP-UX)	cd /
								setboot -b on
								/usr/sbin/shutdown -h -y now |while read line
								do
									echo \"\${line}\"
									[ -n \"\$(echo \"x\${line}\" |grep \"xTransition to run-level 0 is complete\")\" ] && exit 0
								done
								;;
					*)	echo \"\`uname -s\` non supporte\"
						exit 1
						;;
				esac
				"
		REMOTE_VAL=$?

		exit $REMOTE_VAL
	else
		echo "ERROR: can't ping $ARGUMENT_TO_WORK"
		exit 212
fi

