#!/bin/sh


mysql_server=$1
if [ -z "$mysql_server" ]; then
  echo "ERROR: No MySQL-Server to ping given" 1>&2
  exit 1
fi

mysqladmin=$(which mysqladmin)
if [ $? -ne 0 ] ||
   [ -z "$mysqladmin" ]; then
  echo "ERROR: Command 'mysqladmin' not found" 1>&2
  exit 1
fi

$mysqladmin PING --connect_timeout=5 --shutdown_timeout=10 --wait=2 --host="$mysql_server" 2>/dev/null 1>&2
if [ $? -ne 0 ]; then
  echo "WARNING: Mysql-Server '$mysql_server' is unreachable" 1>&2
  exit 1
fi

echo "INFO: Mysql-Server '$mysql_server' is reachable" 1>&2
exit 0

