I'm working on a bash script that requires capturing cookies from web requests.
What I'm Trying to Achieve
- Create a temporary file using
mktemp - Use curl to make a web request
- Capture all cookies set by the server in this temporary file
- Be able to read and use these cookies in subsequent requests
My Current Approach which is working
COOKIE_FILE=~/cookies.txt
curl https://example.com -c "$COOKIE_FILE" -b "$COOKIE_FILE"
Temporary file approach (fails)
COOKIE_FILE=$(mktemp)
curl https://example.com -c "$COOKIE_FILE" -b "$COOKIE_FILE"
and
COOKIE_FILE=$(tempfile --mode=666)
curl https://example.com -c "$COOKIE_FILE" -b "$COOKIE_FILE"
Environment
- vagrantbox - ubuntu/focal64 (virtualbox, 20240821.0.1)
- Linux ubuntu-focal 5.4.0-193-generic #213-Ubuntu SMP Fri Aug 2 19:14:16 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- curl version
curl 8.1.2 (x86_64-pc-linux-gnu) libcurl/8.1.2 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 zstd/1.4.4 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3 libgsasl/1.8.1 Release-Date: 2023-05-30 Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS brotli gsasl GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd - to install this version of curl I followed these steps.
sudo apt purge curl sudo apt autoremove sudo snap install curl