3

I am running command like this.

# ( ( partclone.restore -X -s some.img -o /dev/sda3 2>&3 ) 3>&1 ) | grep Completed
  Completed:  0.40%
  Completed:  1.23%
  Completed:  2.07%
  ...

But I cannot direct the output to a file.

# ( ( partclone.restore -X -s some.img -o /dev/sda3 2>&3 ) 3>&1 ) | grep Completed >> ./log 2>&1

There is nothing in the log file.

But something like cat some.file | grep some.string >> ./log works fine. Why?

4
  • 2
    What if you use ( partclone.restore -X -s some.img -o /dev/sda3 2>&3 ) 3>&1 ) | grep Completed >> ./log ? Jul 11, 2014 at 18:28
  • Could you try ( ( partclone.restore -X -s some.img -o /dev/sda3 2>&3 ) 3>&1 ) | grep Completed | tee ./log
    – Mitch
    Jul 11, 2014 at 18:34
  • Neither of above comments work, I finally end up not using grep but just do "while read output" and do reg-ex on "output" to fetch the string.
    – user276851
    Jul 11, 2014 at 21:33
  • 2
    It is working, the problem is when stdin/stdout aren't terminals, grep buffers the output, grep --line-buffered should work, see for instance stackoverflow.com/q/7161821/2774188 Jul 11, 2014 at 22:10

0

Browse other questions tagged .