Agnus Dei (jackal) wrote,
Agnus Dei

Super Short cgi-bin (shell script) to capture incoming POST data to a file.

Imagine you have an app that runs on the iPad and when it crashes it launches off it's data via a web POST in JSON format to a given URL (which you define and run).

Basically I wrote a simple shell script to capture the input from a WEB POST because POST is converted to standard in via Apache. So a "cat > file" captures all the data. I want to keep the files as raw JSON for parsing later. I prefer them to remain in the JSON format.

Here's my CGI-BIN script:

[webserver:/var/www/html]# cat foo.cgi
TMPFILE=/opt/crashdata/incoming/datafile.`/bin/date +%s%3N` # Epoch time in milliseconds
cat > $TMPFILE ; printf "Content-type: text/html\n\n"

Here's my test:

[desktop:~]$ curl -X POST -H 'Content-Type: application/json' --data @sample-json --insecure --silent

Here's my results:

[webserver:/var/www/html]# cat /opt/crashdata/incoming/datafile.1417732831810
{ "event": "issue_impact_change", "payload_type": "issue", "payload": { "display_id": 123 , "title": "Issue Title" , "method": "methodName of issue", "impact_level": 2, "crashes_count": 54, "impacted_devices_count": 16, "url": "" }}
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened