I'm trying to take data I receive over a netcat connection to a script that will send each line to another server via a curl post command.
Heres where I am.
This works: nc -lk 9272 > test.log
Each line received is in the log as expected
This doesn't work:
nc -lk 9272 | ./senddata.sh
Expect it to send the lines to this script:
#! /bin/bash
echo "Received Line!"
line=$1
cart=${line:0:7}
type=${line:7:4}
title=${line:14:28}
curl -d "cart=$cart&type=$type&title=$title" -X POST http://server/update
Nor does this ./senddata.sh 9272
senddata.sh
#!/bin/bash
echo "Started listening on port $1 ..."
while read line
do
if [ "$line" == 'exit' ]; then
echo "Received 'exit'"
break
else
echo "Received Line!"
cart=${line:0:7}
type=${line:7:4}
title=${line:14:28}
curl -d "cart=$cart&type=$type&title=$title" -X POST http://server/update
fi
done < <((echo "Welcome.") | nc -kl $1)
echo "Good bye"
The end goal is to receive the data and then send it to my app via a post.