The following command works when entered directly on the console:
[root@server user]# curl -d 'parameter=170.22.16.14 192.10.2.24 - - [01/Jan/1900:00:00:00 -0300] "GET /files/notes.txt HTTP/1.1" 200 112061 "-" "Java/1.8.0.160"' -H 'Content-Type: application/x-www-form-urlencoded' -X POST http://192.138.1.10:8080/system/add
On the other side, I have a bash script addinfo.sh
:
#!/bin/bash
tail -n0 -F info.txt | while read LINE; do
ins="curl -d 'parameter=$LINE' -H 'Content-Type: application/x-www-form-urlencoded' -X POST http://192.138.1.10:8080/system/add"
echo $ins
$ins
done
Then I execute the following echo instruction and the output is shown as keeps:
[root@server user]# echo '170.22.16.14 192.10.2.24 - - [01/Jan/1900:00:00:00 -0300] "GET /files/notes.txt HTTP/1.1" 200 112061 "-" "Java/1.8.0.160"' >> info.txt
[root@server user]# curl -d 'parameter=170.22.16.14 192.10.2.24 - - [01/Jan/1900:00:00:00 -0300] "GET /files/notes.txt HTTP/1.1" 200 112061 "-" "Java/1.8.0.160"' -H 'Content-Type: application/x-www-form-urlencoded' -X POST http://192.138.1.10:8080/system/add
curl: option -: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
The HTTP request was not carried out. The following input data cannot be changed:
170.22.16.14 192.10.2.24 - - [01/Jan/1900:00:00:00 -0300] "GET /files/notes.txt HTTP/1.1" 200 112061 "-" "Java/1.8.0.160"
So what can I do in order to correct the Bash script?
bash
and it's just a string forcurl
– Romeo Ninov Feb 24 '23 at 14:46TL;DR
: use$()
form... – Gilles Quénot Feb 24 '23 at 15:31