Skip to content

Instantly share code, notes, and snippets.

@imshvc
Forked from rctay/gist:558851
Last active August 9, 2024 16:39
Show Gist options
  • Save imshvc/eef9ead3a1f2f6b28a9a98b900fe6dd2 to your computer and use it in GitHub Desktop.
Save imshvc/eef9ead3a1f2f6b28a9a98b900fe6dd2 to your computer and use it in GitHub Desktop.
dump mozilla sqlite3 cookies to netscape format
#
# Dumps data from a Mozilla sqlite cookie jar into Netscape cookie format.
#
# Useful if you want to run curl with your browser's cookies.
#
#!/bin/sh
SQLITE=sqlite3
MOZ_PROFILE=$1
MOZ_COOKIE_JAR="$MOZ_PROFILE/cookies.sqlite"
QUERY="select host, path, isSecure, expiry, name, value from moz_cookies;"
HEADER=$(cat <<EOF
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file! Do not edit.
EOF
)
INPUT=$($SQLITE -separator ' ' "$MOZ_COOKIE_JAR" "$QUERY") &&
echo "$HEADER" &&
echo "$INPUT" | awk '
{
F1 = $1 ~ /^\./ ? "TRUE" : "FALSE";
# is secure?
F2 = $3 == "0" ? "FALSE" : "TRUE";
# hmm, we could have used with a join() here, but we are lazy...
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
$1, F1, $2, F2, $4, $5, $6);
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment