Skip to content

Instantly share code, notes, and snippets.

@isaaclw
Last active November 22, 2019 16:06
Show Gist options
  • Save isaaclw/35b11fc5af17b08b2b3d237224006396 to your computer and use it in GitHub Desktop.
Save isaaclw/35b11fc5af17b08b2b3d237224006396 to your computer and use it in GitHub Desktop.
Run Curl with cookies
#!/bin/bash
COOKIE_JAR=cookies.txt
URL="http://www.google.com/foobar/"
get_session() {
read -p "username: " username
# The -s option is only present in bash
read -sp "password: " password
# Get the session cookie (otherwise the post-login cookie test fails)
curl -qL \
--cookie-jar "$COOKIE_JAR" \
"$URL" > /dev/null
# Login
curl -vqLX POST \
-d "__ac_name=$username" \
-d "__ac_password=$password" \
-d "login=Login" \
-d "javascriptEnabled=yes" \
-d "clientTimeZoneOffset=$(date +%:::z)" \
-d "clientTimeZone=$(date +%Z)" \
--cookie "$COOKIE_JAR" \
--cookie-jar "$COOKIE_JAR" \
"$URL" > response.txt
return $?
}
if [ ! -f "$COOKIE_JAR" ]; then
echo "Setting up OT session"
get_session
fi
curl -vkL --cookie "$COOKIE_JAR" --cookie-jar "$COOKIE_JAR" $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment