2

I'm trying to unzip a file and redirect the output to a named pipe and another file. Therefore I'm using the command tee.

gunzip -c $FILE | tee -a $UNZIPPED_FILE > $PIPE

My question is is there any other option to achieve the same but with a command that will write the file asynchronously. I want the output redirected to the pipe immediately and that the writing to the file will run in the background by teeing the output to some sort of buffer.

Thanks in advance

2
  • you already have "some sort of buffer" Commented Jan 7, 2015 at 19:38
  • Sorry that I may have expressed my problem in a complicated way. I'm trying to decouple the file writing from tee so that the output of gunzip will be redirected directly to $PIPE. Therefore I came up with the idea of a buffer that allows this behaviour. Commented Jan 8, 2015 at 9:15

1 Answer 1

1

What you need is a named pipe (FIFO). First create one:

mkfifo fifo 

Now we need a process reading from the named pipe. There's an old unix utillity called buffer that was earlier for asynchronous writing to tape devices. Start a process reading from the pipe in the background:

buffer -i fifo -o async_file -u 100000 -t & 

-i is the input file and -o the output file. The -u flag is only for you to see, that it is really asynchonous. It's a small pause after every write for 1/10 second. And -t gives a summary when finished.

Now start the gunzip process:

gunzip -c archive.gz | tee -a fifo > $OTHER_PIPE 

You see the gunzip process is ending very fast. In the folder you will see the file async_file growing slowly, that's the background process that is writig to that file, the buffer process. When finishing (can take very long with a huge file) you see a summary. The other file is written directly.

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for you answer. As I understand your solution the output will be buffered before the tee command. I only want to buffer the output for the file not for writing it to the pipe.
No I'm looking for a way to unzip a file and redirect the output to file on disk and to a named pipe. The problem is that the disk I/O is way too slow and I want to write the output to the disk asynchronously and write to the pipe directly.
@what I misunderstood you question sorry. Now it should be correct.
Thank you for your answer. The only problem I still have that I do not have the rights to install buffer. Will it make any differences using cat fifo > aysnc_file & ?
I don't see a way around that. Maybe you could try it with dd, but definitely not with cat. buffer loads everything into shared memory and that's why buffer is not blocking compared to cat.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.