2

There are a few commands that print some status lines in the console when they are doing something (ffmpeg or fsarchiver).

-[00][  0%][DIR     ] /boot/grub/fonts
-[00][  0%][REGFILE ] /boot/grub/fonts/unicode.pf2
-[00][  0%][REGFILEM] /boot/grub/grubenv
-[00][  0%][REGFILEM] /boot/grub/grub.cfg
-[00][  0%][REGFILE ] /boot/initrd.img-4.13.0-16-generic

Now i want to build a script that makes use of these commands but the output will purge away the script messages very fast. I know that there are other commands like the new apt or wget that show progress in one line that continously updates.

I already played a little with such one line status lines in my script finding out that instead of newlines \n i need to place carriage returns \r which totally makes sense.

Then i tried to do the same with the commands (ffmpeg or fsarchiver) piping the ouput to tr "\n" "\r" . But i found out that this does not change something.

Is there any way to get a one line status line out of such commands?

Regards

laubed
  • 21
  • 2
  • 1
    I need a more precise description of the problem (intended vs. seen output) in order to help you. And you should provide a way to generate suitable test output with generally available software. – Hauke Laging Jan 18 '18 at 21:43
  • 1
    Example command to generate output: `while true; do date; sleep 1; done` After each second the last line should be replaced with the next in sequence – laubed Jan 18 '18 at 21:47

2 Answers2

1

It is a buffering problem:

while true; do date; sleep 1; done | stdbuf --output=0 tr '\n' '\r'
Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • 1
    That works but if the command that is run has different output lengths than a shorter line won't override the whole previous line. – laubed Jan 19 '18 at 16:30
0

It sounds like you basically answered your own question. When you pipe output to tr, did you pipe BOTH stdout AND stderr?

user1404316
  • 3,028
  • 12
  • 23
  • That improved the situation a bit but if the previous line is longer than the next a part of the older line is not cleared – laubed Jan 18 '18 at 21:06
  • You can use terminal escape sequences to clear the line. For example, `echo -e "\033[2K"` should clear the entire line. – user1404316 Jan 18 '18 at 21:35