From 34bb501be08aa2b313d88e67d6e0a7e0a3f9cfa6 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 5 May 2024 00:07:30 +0200 Subject: New upstream version 1.47.90 --- contrib/scripts/NM-log | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 contrib/scripts/NM-log (limited to 'contrib/scripts/NM-log') diff --git a/contrib/scripts/NM-log b/contrib/scripts/NM-log new file mode 100755 index 00000000..85faea86 --- /dev/null +++ b/contrib/scripts/NM-log @@ -0,0 +1,85 @@ +#!/bin/bash + +# Util to pretty-print logfile of NetworkManager +# +# Unless setting NM_LOG_NO_COLOR it will colorize the output. +# Suppress coloring with: +# $ NM_LOG_NO_COLOR=1 NM-log ... +# +# If called without arguments, it either reads from stdin (if not +# connected to a terminal) or it shows the journal content. +# +# If called with first argument "j", it always shows the journal content. +# +# You can pass multiple filenames. + +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + NM_not_sourced=1 +else + unset NM_not_sourced +fi + +NM-show-journal() { + local since="$(systemctl show NetworkManager | sed -n 's/^ExecMainStartTimestamp=\(.*\) [A-Z0-9]\+$/\1/p')" + + if [[ "$since" == "" ]]; then + echo "error detecting NM. Is it running?" + systemctl status NetworkManager + else + journalctl -o short-precise --since "$since" -b 0 -u NetworkManager "$@" + fi +} + +NM-colorize() { + if [[ "$NM_LOG_NO_COLOR" == "" ]]; then + # poor man's coloring using grep. + # TODO: do it somehow better (and more efficient). + sed 's/\r$//' | \ + GREP_COLOR='01;31' grep -a --color=always '^\|^\(.* \)\?<\(warn> \|error>\) \[[0-9.]*\]' | \ + GREP_COLOR='01;33' grep -a --color=always '^\|^\(.* \)\? \[[0-9.]*\]\( .*\.*$\)\?' | \ + GREP_COLOR='01;37' grep -a --color=always '^\|\\|\