From 8f31634df6099f6f027b87e48d27ecd206dea037 Mon Sep 17 00:00:00 2001 From: Pierre Gaxatte <30696904+pgaxatte@users.noreply.github.com> Date: Sat, 15 Sep 2018 15:45:10 +0200 Subject: [PATCH] feat(batch): Add a batch short option for one line result (#243) When using this script on a large amount a machine (via clustershell or instance) it can be easier to have a very short result on one line showing only the vulnerabilities --- spectre-meltdown-checker.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index de594ad..cb660c3 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -68,6 +68,7 @@ show_usage() --arch-prefix PREFIX specify a prefix for cross-inspecting a kernel of a different arch, for example "aarch64-linux-gnu-", so that invoked tools will be prefixed with this (i.e. aarch64-linux-gnu-objdump) --batch text produce machine readable output, this is the default if --batch is specified alone + --batch short produce only one line with the vulnerabilities separated by spaces --batch json produce JSON output formatted for Puppet, Ansible, Chef... --batch nrpe produce machine readable output formatted for NRPE --batch prometheus produce output for consumption by prometheus-node-exporter @@ -642,7 +643,7 @@ while [ -n "$1" ]; do opt_no_color=1 shift case "$1" in - text|nrpe|json|prometheus) opt_batch_format="$1"; shift;; + text|short|nrpe|json|prometheus) opt_batch_format="$1"; shift;; --*) ;; # allow subsequent flags '') ;; # allow nothing at all *) @@ -741,6 +742,7 @@ pvulnstatus() case "$opt_batch_format" in text) _echo 0 "$1: $2 ($3)";; + short) short_output="${short_output}$1 ";; json) case "$2" in UNK) is_vuln="null";; @@ -3423,6 +3425,10 @@ if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "nrpe" ]; then fi fi +if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "short" ]; then + _echo 0 "${short_output% }" +fi + if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "json" ]; then _echo 0 "${json_output%?}]" fi