You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Princeton/pu/libexec/check_by_ssh_ng

29 lines
482 B
Bash

#!/bin/bash
if [[ "$#" -lt "4" ]]; then
echo "Usage: $0 <path_to_keyfile> <remoteuser> <remotehost> <remotecommand> [regex_to_match_expected]"
exit 3
fi
key=$1
usr=$2
host=$3
command=$4
expect=$5
command=`echo "$command" | sed 's/%%%%pipe%%%%/|/'`
##echo "###$command###"
ret=`/usr/bin/ssh -i $key ${usr}@${host} "$command" 2>&1`
stat=$?
if [[ "$stat" -eq "0" && ("$ret" =~ $expect || -z "$expect") ]]
then
echo "OK: $ret"
else
echo "CRITICAL: $ret"
stat=2
fi
exit $stat