Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] bash output buffering



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




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org