[英]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
我正在使用一個名為 PRTG 的監控系統來監控我們的環境。 PRTG KB 建議使用腳本來監視名為 SSH 腳本的進程。 該腳本需要存儲在/var/prtg/scripts 中。
我找到了一個有人用於 PRTG 的腳本:
#!/bin/sh
pgrep wrapper $1 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "1:$?:$1 Down"
else
echo "0:$?:OK"
fi
但是,PRTG 在 Web GUI 中返回以下錯誤代碼:
響應格式不正確:“pgrep:只能提供一種模式嘗試‘pgrep --help’以獲取更多信息。1:0:Wrapper Down”
但是,當我在 Linux 服務器上運行腳本時,它會打印出:
0:1:好
所以我的問題是什么是最好的腳本來告訴 PRTG 一個進程是“向下”還是“向上”?
################### 編輯以進一步說明:
我更改了腳本,它在命令行上運行得非常好……但問題似乎在於 PRTG 如何讀取 output。顯然它的格式不正確。 所以這是我的腳本:
#!/bin/bash
SERVICE="wrapper"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE is running"
else
echo "$SERVICE stopped"
fi
這是 PRTG 的錯誤:
Response not well-formed: "wrapper is running "
所以...PRTG 說我正在使用的傳感器需要將腳本 output 轉換為這種格式:
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
所以我想現在……問題是我如何將該腳本發送到 output PRTG 想要看到的內容?
根據您對腳本所做的更改,應該如下所示,並像下面這樣調用: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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.