From 7c49b2240b35480dd9d720b15cba6ec9ea1c20b3 Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Wed, 16 Oct 2024 01:25:32 +0400 Subject: [PATCH] updated ssh_dump_logs.sh --- monitoring/ssh_dump_logs.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/monitoring/ssh_dump_logs.sh b/monitoring/ssh_dump_logs.sh index 73d99d37bbb..3308b7d1340 100755 --- a/monitoring/ssh_dump_logs.sh +++ b/monitoring/ssh_dump_logs.sh @@ -78,19 +78,21 @@ for user_server in "$@"; do tstamp="$(date '+%F_%H%M')" #for log in messages secure dmesg; do for log in messages dmesg; do - log_file="log.$tstamp.$server.$log.txt" + log_file="log.$tstamp.$server.$log.txt.gz" # ignore && && || it works # shellcheck disable=SC2015 timestamp "Dumping server '$server' log: $log" && - # TODO: optimize by gzip compressing these logs on the server size + sudo="" if ! [[ "$server" =~ ^root@ ]]; then - # want client side expansion - # shellcheck disable=SC2029 - ssh ${SSH_KEY:+-i "$SSH_KEY"} ${user:+"$user@"}"$server" "sudo cp -v /var/log/$log ~/$log_file && sudo chown -v \$USER ~/$log_file" && - scp ${SSH_KEY:+-i "$SSH_KEY"} ${user:+"$user@"}"$server":"./$log_file" . - else - scp ${SSH_KEY:+-i "$SSH_KEY"} ${user:+"$user@"}"$server":"/var/log/$log" "$log_file" - fi && + sudo=sudo + fi + # want client side expansion + # shellcheck disable=SC2029 + ssh ${SSH_KEY:+-i "$SSH_KEY"} ${user:+"$user@"}"$server" " + $sudo gzip -c /var/log/$log > ~/$log_file && + $sudo chown -v \$USER ~/$log_file + " && + scp ${SSH_KEY:+-i "$SSH_KEY"} ${user:+"$user@"}"$server":"./$log_file" . timestamp "Dumped server '$server' log to file: $log_file" || warn "Failed to get '$server' log: $log" # XXX: because race condition - spot instances can go away during execution