Skip to content

Instantly share code, notes, and snippets.

@jewzaam
Created January 20, 2021 20:04
Show Gist options
  • Save jewzaam/63ab872ca913c9fc23fa0e16c89d1055 to your computer and use it in GitHub Desktop.
Save jewzaam/63ab872ca913c9fc23fa0e16c89d1055 to your computer and use it in GitHub Desktop.
Dump node-logs into current directory
#!/bin/bash
# simple script to dump node-logs to the current directory
echo "Downloading audit log files.."
NODES=$(oc get nodes | grep master | awk '{print $1}')
# create dirs for each node
# collect all the logs, do in parallel
for LOG_PATH in openshift-apiserver kube-apiserver;
do
for NODE in $NODES
do
mkdir -p $NODE/$LOG_PATH
done
IFS_OLD=$IFS
IFS=$'\n'
for CMD in $(oc adm node-logs --role=master --path=$LOG_PATH/ | grep -v "\.terminating" | awk "{print \"oc adm node-logs \" \$1 \" --path=$LOG_PATH/\" \$2 \" > \" \$1 \"/$LOG_PATH/\" \$2
}");
do
eval $CMD &
done
IFS=$IFS_OLD
done
JOB_COUNT=100
# wait on count > 2 because the ps command is counted as a child and a little slop..
while [ $JOB_COUNT -gt 2 ];
do
BYTES=$(du --max-depth=0 | awk '{print $1}')
JOB_COUNT=$(ps --no-headers -o pid --ppid=$$ | wc -w)
printf "\rBytes downloaded: $BYTES"
sleep 1
done
echo ""
# wait for any commands to finish up
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment