Skip to content

Instantly share code, notes, and snippets.

@rctay
Created August 31, 2010 10:39
Show Gist options
  • Save rctay/558851 to your computer and use it in GitHub Desktop.
Save rctay/558851 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=//path//to//sqlite3.exe
MOZ_PROFILE="C:\\path\\to\\mozilla\\profile"
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