<div class="gmail_quote">On Wed, Jan 12, 2011 at 4:33 PM, - Tethys <span dir="ltr"><<a href="mailto:tethys@gmail.com">tethys@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Does anyone know of a simple delay utility that consumes data from<br>
stdin and outputs it on stdout a fixed time later? What I want to be<br>
able to do is:<br>
<br>
mkdata | delay 30 | send_data_to_customer<br>
<br>
That will send the (time sensitive) output of mkdata to the customer<br>
with a 30 second delay. The amount of data I'm talking about isn't so<br>
large that I need to worry about memory usage, and buffering it in RAM<br>
will work just fine. I can write it myself, but I'd rather not<br>
reinvent the wheel if someone's already done it.<br></blockquote><div><br>You could pipe it through a series of netcats such that the latency along the path is 30 seconds. 50 roundtrips to japan should do it. ;-)<br>
<br>It's sortof an interesting problem as to do it properly you really need to timestamp every read().<br><br>You could perhaps create artificial latency using netem perhaps making the nc idea almost practical.<br><br>
Here's some crappy perl I made that may work. I think.<br><br>use IO::Select;<br><br>my $delay = 30;<br>my @stuff = ();<br><br>my $s = IO::Select->new();<br>$s->add(\*STDIN);<br>while(1)<br>{<br><br> if ($s->can_read(1) )<br>
{<br> sysread(STDIN, $chunk, 1024);<br> push @stuff, { time=>time(), chunk=>$chunk };<br> }<br><br> if (my $test = shift(@stuff))<br> {<br><br> if ($test->{time} <= (time()-$delay) )<br> {<br> print $test->{chunk};<br>
} else { unshift(@stuff, $test); }<br><br> }<br>}<br><br><br><br><br>Rob<br><br></div></div><br>