#!/bin/bash
# a command to check if it's possible to ssh to a host
# requires passwordless auth
# thanks to admin@kbni.net
args=(-f -o BatchMode=yes -o ConnectTimeout=15)
if [[ $1 == -i ]]; then
    # insecure mode
    args=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null)
    shift
fi
host=${1?Need host}

ssh "${args[@]}" $host exit &> /dev/null
status=$?
if (( status == 0 )); then
    echo ok
else
    echo FAIL
fi
exit $status

