0

I have a rake take I run like this

be rake fix_pf_administrator_pct_assets

The rake task is part of a larger rails app.

There's a loop in the code, and a sleep 1, so I get a very "real time" output of the script.

However, if I do this

be rake fix_pf_administrator_pct_assets | grep mydebugprint

I have to wait till the whole script finishes before seeing the results.

How can I have real-time output of the script, while being able to grep for interesting lines.

american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80
  • Try with the second option on the first answer in this question https://stackoverflow.com/questions/20135059/bash-reading-stdout-stream-in-real-time – arieljuod Aug 27 '18 at 21:02
  • Basically, it runs the script outputing on a file called `output`, then moves the process to the background with `&`, then runs `tail -f` on that file to follow the changes and theeen it greps the output – arieljuod Aug 27 '18 at 21:04

1 Answers1

1

If you're on a systetm with GNU coreutils, you can force the output of the rake task to be line buffered: (assumes "be" is not a shell alias but a command)

stdbuf --output=L be rake fix_pf_administrator_pct_assets | grep mydebugprint

stdbuf(1) man page

glenn jackman
  • 238,783
  • 38
  • 220
  • 352