Created
January 18, 2019 03:19
-
-
Save chrisdlangton/142fa3734bec15f34830ab120507c289 to your computer and use it in GitHub Desktop.
Script to dump the entire cert.sh database as CSV
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
#!/usr/bin/env bash | |
SCHEMA=public | |
DB=certwatch | |
HOST=crt.sh | |
PORT=5432 | |
USER='guest --no-password' | |
DIR=$(pwd) | |
mkdir -p $DIR | |
psql -h $HOST -p $PORT -U $USER -Atc "select tablename from pg_tables where schemaname='$SCHEMA'" $DB |\ | |
while read TBL; do | |
echo "Checking $TBL" | |
if [ ! -f "$DIR/$TBL.csv" ]; then | |
psql \ | |
-h $HOST \ | |
-p $PORT \ | |
-U $USER \ | |
-c "COPY $SCHEMA.$TBL TO STDOUT DELIMITER ',' CSV HEADER" $DB \ | |
> $DIR/$TBL.csv.part && \ | |
mv $DIR/$TBL.csv.part $DIR/$TBL.csv | |
else | |
echo "$TBL.csv Exists" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment