pull down to refresh

Nice script!
It is enough to do a much-more compatible #!/bin/sh since you are not using any Bash-specific features in the script. Also you can use jq -c '.[] | select (.status != "active")' for brevity.
The full smaller (maybe not simpler, but your mileage may vary) script which does the same in significantly shorter time is:
#!/bin/sh # # A script to extract stale blocks (height, hash, header) from a # Bitcoin Core node. Output is in CSV format. # This assumes .cookie-file authentication to the Bitcoin Core node. bitcoin-cli getchaintips \ | jq -rc '.[] | select (.status != "active") | ( (.height | tostring) + " " + .hash )' \ | while read height bhash; do echo "$height,$bhash,$(bitcoin-cli getblockheader $bhash false)" done
Comparison of both:
$ time sh script.sh | sha256sum real 0m 4.98s user 0m 4.60s sys 0m 0.25s 678d9d530cd9cb8d41a45fbb210084dd5601b04a2313bae8d1f564b7eb1f203f - $ time sh script-small.sh | sha256sum real 0m 0.35s user 0m 0.30s sys 0m 0.04s 678d9d530cd9cb8d41a45fbb210084dd5601b04a2313bae8d1f564b7eb1f203f -
The output of my bitcoin-cli getchaintips is shorter than yours.
@k00b please note the copy&paste of preformatted text blocks (whose line-numbers indentation was fixed recently, thanks!) gives line-numbers:
#!/bin/bash 2 3# A script to extract stale blocks (height, hash, header) from a 4# Bitcoin Core node. Output is in CSV format. 5# This assumes .cookie-file authentication to the Bitcoin Core node.
Oh, neat. Thanks! Will adopt the script if you don't mind.
Note: There's also the invalid status in getchaintips when you've used invalidateblock.