Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a program in a pipe not to be executed until the first data arrive without tempfile?

Tags:

bash

curl

pipe

Specific case:

generate_data | curl -T - http://someserver/path

That means, I have a program that generate an output in the stdout, and I put that on a remote server with curl.

The problem is that if generate_data takes too much time, the server is going to return 408.

I know that pipes execute all the commands without waiting for data to be ready, so my next iteration was:

generate_data | ( sleep 20 ; curl -T - http://someserver/path )

The time was twice the max time needed to run generate_data, so all the things are ok. But... it is not a optimal solution.

I know I can create something more complex with read, and a proper shell script, but have the feeling that I an missing something obvious.

So... What can i use instead of the sleep 20; without creating a temp file?

like image 684
Guillermo Avatar asked Nov 04 '22 11:11

Guillermo


1 Answers

generate_data > /tmp/generated_data; cat /tmp/generated_data | curl -T - http://someserver/path
like image 63
mbarrows Avatar answered Nov 15 '22 05:11

mbarrows