blob: c71682bcc4a56fe2150a55bb02dc6ea42e9af54c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/bin/sh -e
for line in $(systemctl show -p SystemState,NFailedUnits); do
split_idx="$(printf "%s" "$line" | awk '{print index($0, "=")}')"
property="$(printf "%s" "$line" | awk '{print substr($0, 1, '"$split_idx"' - 1)}')"
value="$(printf "%s" "$line" | awk '{print substr($0, '"$split_idx"' + 1)}')"
case "$property" in
"SystemState")
SYSTEM_STATE="$value"
;;
"NFailedUnits")
FAILED_UNITS="$value"
;;
*)
;;
esac
done
if [ -z "$SYSTEM_STATE" ] || [ -z "$FAILED_UNITS" ]; then
echo "$0: failed to get expected data from system." >&2
exit 3
fi
printf "SYSTEM %s: %d units failed.\n" "$SYSTEM_STATE" "$FAILED_UNITS"
[ "0" = "$FAILED_UNITS" ] || exit 2
|