#!/bin/ash

pgrep ssh
if [ $? -eq 0 ]; then
  echo "Process is running."

  HOST="develop.getin.mx"
  HOSTNAME=`cat /proc/sys/kernel/hostname`
  PORT=5${HOSTNAME:5}
  if [ ${PORT} -eq 5 ]; then
      PORT=50000
  fi

  ssh -i /usr/local/allshoppings-cportal/id_rsa_getin -y bluemark@${HOST} "netstat -an | grep ::1:${PORT}"
  if [ $? -eq 0 ]; then
    echo "Tunnel is open."
  else
    echo "Tunnel is not open."
    /etc/init.d/dnsmasq restart
    /etc/init.d/watchdog restart
  fi

else
  echo "Process is not running."
  /etc/init.d/dnsmasq restart
  /etc/init.d/watchdog restart
fi

