Skip to content
Snippets Groups Projects
Commit 486a0e1d authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'fix-specialchars-systemd' into 'master'

remove special chars from systemd status

See merge request !191
parents dde54092 6507d7d3
Branches
No related tags found
1 merge request!191remove special chars from systemd status
......@@ -9,11 +9,12 @@
# 2020-09-06 v1.2 <axel.hahn@unibe.ch> add param -r to use a regex
# 2020-09-18 v1.3 <axel.hahn@unibe.ch> fix: list units --all to show all stopped units
# 2020-09-18 v1.4 <axel.hahn@unibe.ch> replace pipes in systemctl status output
# 2020-10-20 v1.5 <axel.hahn@unibe.ch> remove special chars from systemd status
# ================================================================================
. $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.4
export self_APPVERSION=1.5
# ----------------------------------------------------------------------
# FUNCTIONS
......@@ -127,13 +128,16 @@ fi
# --- check given unit
_status=$( systemctl --no-pager -l status "${_unit}" 2>&1 | tr '|' ':' )
_data=$( systemctl --no-pager -l status "${_unit}" 2>&1 | tr '|' ':' )
if ! grep "Active: active (running) " <<< "${_status}" >/dev/null; then
_status=$( echo "$_data" | head -1 | sed "s#^[^a-zA-Z]*##g" )
if ! grep "Active: active (running) " <<< "${_data}" >/dev/null; then
ph.setStatus critical
fi
ph.status "${_status}"
echo "$_data" | sed -n "2,\$p" | tr -d '└├' | tr '─' '-'
ph.exit
# ----------------------------------------------------------------------
......@@ -16,7 +16,7 @@ A unit is everything listed by systemctl command - services, timers, targets, ..
______________________________________________________________________
CHECK_SYSTEMDUNIT
v1.4
v1.5
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -89,17 +89,17 @@ To check a single service you need to add the unit name in the 1st column.
``$ ./check_systemdunit nginx`` returns
```txt
OK: nginx.service - A high performance web server and a reverse proxy server
OK: nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-09-05 08:04:45 CEST; 8h ago
Process: 577 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=0/SUCCESS)
Main PID: 612 (nginx)
Active: active (running) since Fri 2023-10-20 08:04:35 CEST; 3h 14min ago
Process: 783 ExecStart=/usr/bin/nginx (code=exited, status=0/SUCCESS)
Main PID: 787 (nginx)
Tasks: 2 (limit: 18881)
Memory: 3.0M
CPU: 38ms
Memory: 3.8M
CPU: 39ms
CGroup: /system.slice/nginx.service
├─612 "nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;"
└─613 "nginx: worker process"
-787 "nginx: master process /usr/bin/nginx"
-788 "nginx: worker process"
...
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment