From 04300838a47bc42c2f9ffad2dc5d89bf0cace44e Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Thu, 25 Feb 2021 14:14:18 +0200 Subject: [PATCH] [generate_dump] allow to extend dump with plugin scripts. (#1335) - What I did Added support for tech support extension scripts. - How I did it It looks at /usr/bin/debug-dump for scripts, if it finds one it will execute them and save the output to dump/ folder. - How to verify it Write a simple scripts that outputs something and place it under /usr/bin/debug-dump/ Signed-off-by: Stepan Blyshchak --- scripts/generate_dump | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 79489eb2f3..ec23d93040 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -32,6 +32,7 @@ DUMPDIR=/var/dump TARDIR=$DUMPDIR/$BASE TARFILE=$DUMPDIR/$BASE.tar LOGDIR=$DUMPDIR/$BASE/dump +PLUGINS_DIR=/usr/local/bin/debug-dump NUM_ASICS=1 HOME=${HOME:-/root} USER=${USER:-root} @@ -138,6 +139,7 @@ save_bcmcmd_all_ns() { # cmd: The command to run. Make sure that arguments with spaces have quotes # filename: the filename to save the output as in $BASE/dump # do_gzip: (OPTIONAL) true or false. Should the output be gzipped +# save_stderr: (OPTIONAL) true or false. Should the stderr output be saved # Returns: # None ############################################################################### @@ -148,10 +150,17 @@ save_cmd() { local filename=$2 local filepath="${LOGDIR}/$filename" local do_gzip=${3:-false} + local save_stderr=${4:-true} local tarpath="${BASE}/dump/$filename" local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" + local redirect="&>" [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR + if ! $save_stderr + then + redirect=">" + fi + # eval required here to re-evaluate the $cmd properly at runtime # This is required if $cmd has quoted strings that should be bunched # as one argument, e.g. vtysh -c "COMMAND HERE" needs to have @@ -171,9 +180,9 @@ save_cmd() { fi else if $NOOP; then - echo "${timeout_cmd} $cmd &> '$filepath'" + echo "${timeout_cmd} $cmd $redirect '$filepath'" else - eval "${timeout_cmd} $cmd" &> "$filepath" + eval "${timeout_cmd} $cmd" "$redirect" "$filepath" if [ $? -ne 0 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." fi @@ -1076,6 +1085,12 @@ main() { save_cmd "docker ps -a" "docker.ps" save_cmd "docker top pmon" "docker.pmon" + local -r dump_plugins="$(find ${PLUGINS_DIR} -type f -executable)" + for plugin in $dump_plugins; do + # save stdout output of plugin and gzip it + save_cmd "$plugin" "$(basename $plugin)" true false + done + save_saidump if [[ "$asic" = "mellanox" ]]; then