简体   繁体   中英

I need help creating a shell script to tell me if a process is up and running so I can monitor that process in PRTG

I'm using a monitoring system called PRTG to monitor our environment. PRTG KB suggested using a script to monitor processes called SSH Script. The script needs to be stored in /var/prtg/scripts.

I found a script that someone used for PRTG:

#!/bin/sh

pgrep wrapper $1  2>&1 1>/dev/null

if [ $? -ne 0 ]; then
  echo "1:$?:$1 Down"
else
  echo "0:$?:OK"
fi

However, PRTG is returning the following error code within the Web GUI:

Response not well-formed: "pgrep: only one pattern can be provided Try `pgrep --help' for more information. 1:0:Wrapper Down "

However, when I run the script on the Linux server it prints out:

0:1:OK

So my question would be what would be the best script to use to tell PRTG that a process is "Down" or "UP"?

################### Editing for further clarification:

I changed the script up and it works awesome on the command line...but it appears that the issue is with how PRTG is reading the output. Apparently it's not in the correct format. So here's my script:

#!/bin/bash
SERVICE="wrapper"
if pgrep -x "$SERVICE" >/dev/null
then
    echo "$SERVICE is running"
else
    echo "$SERVICE stopped"
fi

This is what PRTG is erroring out with:

Response not well-formed: "wrapper is running "

So...PRTG is saying that the sensor I'm using wants the script output into this format:

The returned data for standard SSH Script sensors must be in the following 
format:

returncode:value:message

Value has to be a 64-bit integer or float. It is used as the resulting value 
for this sensor (for example, bytes, milliseconds) and stored in the 
database. The message can be any string (maximum length: 2000 characters).

The SSH script returncode has to be one of the following values:

VALUE                                  DESCRIPTION

 0                                         OK
 1                                       WARNING
 2                                     System Error
 3                                    Protocol Error
 4                                     Content Error

So I guess now...the question is how do I get that script to output what PRTG wants to see?

From the changes you made to the script, is shall look like below, and called like this example: servicecheck.sh sshd

#!/bin/sh

pgrep -x $1  2>&1 1>/dev/null

if [ $? -ne 0 ]; then
  echo "1:$?:$1 Down"
else
  echo "0:$?:OK"
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM