Using CURL to download file and view headers and status code

Viewed 23141

I'm writing a Bash script to download image files from Snapito's web page snapshot API. The API can return a variety of responses indicated by different HTTP response codes and/or some custom headers. My script is intended to be run as an automated Cron job that pulls URLs from a MySQL database and saves the screenshots to local disk.

I am using curl. I'd like to do these 3 things using a single CURL command:

  1. Extract the HTTP response code
  2. Extract the headers
  3. Save the file locally (if the request was successful)

I could do this using multiple curl requests, but I want to minimize the number of times I hit Snapito's servers. Any curl experts out there?

Or if someone has a Bash script that can respond to the full documented set of Snapito API responses, that'd be awesome. Here's their API documentation.

Thanks!

2 Answers
Related