I'm trying to write a simple handler for a webhook using xinetd and bash. I have the trivial case working with this config for xinetd:
service github-hooks
{
port = 61000
socket_type = stream
protocol = tcp
wait = no
user = ubuntu
server = /home/ubuntu/github-hooks.sh
}
and this bash script:
#!/bin/bash
echo -e "HTTP/1.1 200 OK"
now, I want to read in the post data that is being sent in the webhook so I can do something more interesting that always returning 200.
How do I do read the post data from my bash script?
I've tried:
while read line; do
echo "$line" >> /home/ubuntu/test
done < /dev/stdin
but that is not working for me.
Edit
Thanks to the suggestion below, I stopped xinetd
and used nc
to see what raw data was coming over the wire:
$nc -l 61000
and got this:
POST / HTTP/1.1
Host: <snip>:61000
Accept: */*
User-Agent: GitHub-Hookshot/375c44e
X-GitHub-Event: pull_request
X-GitHub-Delivery: 2dc1fb00-1c8e-11e6-9955-64afafb6ce32
content-type: application/json
X-Hub-Signature: sha1=45afd85b7d4312fa8ac4c56638e8e9699e2ddb36
Content-Length: 20558
{"action":"opened","number":116,"pull_request": <snip>
So, the data is being sent. Now, Knowing that there are exactly 11 lines being sent, I read exactly 11 lines:
for i in {0..10}
do
read line
echo "$line" >> /home/ubuntu/test
done
And, I get the same output (great success :)
POST / HTTP/1.1
Host: <snip>:61000
Accept: */*
User-Agent: GitHub-Hookshot/375c44e
X-GitHub-Event: pull_request
X-GitHub-Delivery: 2dc1fb00-1c8e-11e6-9955-64afafb6ce32
content-type: application/json
X-Hub-Signature: sha1=45afd85b7d4312fa8ac4c56638e8e9699e2ddb36
Content-Length: 20558
{"action":"opened","number":116,"pull_request": <snip>
Maybe I should just read 9 lines then use the Content-Length
parameter to read the rest? I still don't really understand what's going on so any information would be very helpful.