Last active
September 2, 2021 06:31
-
-
Save anonymouse64/90b30502ffa3093f77d9a48d9f1d5e8a to your computer and use it in GitHub Desktop.
stream gce serial console output continuously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
INSTANCE="$1" | |
if [ -z "$INSTANCE" ]; then | |
echo "first argument must be the GCE instance" | |
exit 1 | |
fi | |
next=0 | |
truncate -s0 console-output.txt | |
while true; do | |
next=$( | |
gcloud compute \ | |
--project=snapd-spread \ | |
instances get-serial-port-output \ | |
--start="$next" \ | |
"$INSTANCE" \ | |
--zone=us-east1-b 3>&1 1>"console-output-bits.txt" 2>&3- | grep -Po -- '--start=\K[0-9]+') | |
trimmedConsoleSnippet="$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' < console-output-bits.txt)" | |
if [ -n "$trimmedConsoleSnippet" ]; then | |
echo "$trimmedConsoleSnippet" >> console-output.txt | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment