[Discuss] bash output buffering

Kevin D. Clark kevin_d_clark at comcast.net
Wed Jun 13 11:52:47 EDT 2012


Edward Ned Harvey writes:

> A command inside of bash generates output every second (ping) redirected to
> a file.
> If you run the command on an interactive shell, then you can tail -f the
> file, and see the output "live" as it happens.
> But if you run the command inside an "at" script, or a cron script, you tail
> -f the file...  And nothing appears for a few minutes, and then it all
> appears suddenly.


An easy solution might be to do something like this:

    $ cat pingtest 
    #!/bin/sh
    
    rm -f /tmp/output
    
    while /bin/true ; do 
      ping -c 1 your-test-machine >>/tmp/output
      sleep 1
    done
    
    $ at -f pingtest 'now + 1 minute'
    job 4 at Wed Jun 13 11:49:00 2012


Sure, you could go messing around with a LD_PRELOAD hack, but that
might be more hassle than you need for this task.

Hope this helps,

--kevin
-- 
alumni.unh.edu!kdc / http://kdc-blog.blogspot.com/
GnuPG: D87F DAD6 0291 289C EB1E 781C 9BF8 A7D8 B280 F24E

And the Army Ants, they leave nothin' but the bones...
   -- Tom Waits




More information about the Discuss mailing list