#!/bin/bash # This script checks the running processes of a remote host by SSH # You have to add the public-Key of the user running this script (usually nagios) # to the remote authorized_keys of the user on the remote system. # This script only needs the privilege to run "ps -e -o cmd" on the remote system # This script is released under the terms of the GPL # Have fun, everyone, neuhaus@dodekatex.de usage="Usage: check_process_by_ssh -H Host -k SSH_public_keyfile -u SSH_user [-p SSH_port] service1 [service2 service3 ...]" sshport="22" sshhostname="" sshkeyfile="" sshuser="" process=() while getopts "H:p:k:u:" opt; do case $opt in H ) sshhostname=$OPTARG ;; p ) sshport=$OPTARG ;; k ) sshkeyfile=$OPTARG;; u ) sshuser=$OPTARG;; \? ) echo $usage exit 1;; esac done shift $(($OPTIND - 1)) if [ -z "$1" ] || [ -z "$sshhostname" ] || [ -z "$sshkeyfile" ] || [ -z "$sshuser" ]; then echo $usage exit 1 fi # Now, everything's fine with the arguments. Let's start to work process=$(ssh -l $sshuser -p $sshport -i $sshkeyfile $sshhostname ps -e -o cmd) while [ ! -z "$1" ] ; do tempok="false" for i in $process ; do if echo $i | grep -s $1 2> /dev/null > /dev/null ; then tempok="true" ok="${ok} $1" break fi done if [ $tempok = false ] ; then error="${error} $1" fi shift done if [ -z $error ] ; then echo "$ok running" exit 0 else echo "$error missing" exit 2 fi