1

I wanted to prepend the output (progress) of rclone with custom text. After some googling I've come up with this solution:

rclone sync "$SOURCE" "$DESTINATION" | while read line; do echo " $line"; done 

But actually rclone (with --progress) grabs some lines at start and then just updates them during its execution. But using while I end up with constant adding new lines instead of updating old ones. Does anybody know how to fix it ?

Default rclone --progress output, it is updated every second:

Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - Checks: 97 / 97, 100% Elapsed time: 0.0s 

Desired output:

[My text] Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - [My text] Checks: 97 / 97, 100% [My text] Elapsed time: 0.0s 

Actual result with while, it does NOT update, it adds instead:

[My text] Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - [My text] Checks: 97 / 97, 100% [My text] Elapsed time: 0.0s [My text] Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - [My text] Checks: 97 / 97, 100% [My text] Elapsed time: 0.0s [My text] Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - [My text] Checks: 97 / 97, 100% [My text] Elapsed time: 0.0s [My text] Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - [My text] Checks: 97 / 97, 100% [My text] Elapsed time: 0.0s 
0

2 Answers 2

0

I'm not sure if I understood your question. If what you want to do is constantly update the same line, you can use something like:

rclone sync "$SOURCE" "$DESTINATION" | while read line; do echo -en " \r$line"; done 

-n will stop echo to print the trailing newline

-e will instruct echo to evaluate backslash sequences

1
  • I've supplemented description with an example Commented Jun 16, 2020 at 10:43
0

It is difficult to control this type of updating, mainly because not all programs send the full update data and always in the same position. In this particular case, rclone seems to send the three full data lines every second, so we have to modify them AND also redraw in the same position erasing the old ones, because if the newer are shorter than the older they will mix on the screen. For me, the easiest way is using the clear command and show only the data lines in the upper left corner each redrawing:

rclone sync "$SOURCE" "$DESTINATION" | while read line; do if echo "$line" | grep -q "Transferred"; then clear; fi ; echo " $line"; done 

If we want more control, we can use ANSI escape cursor position codes to precisely put each specific output line in some predefined screen position, using grep to determine which line is currently being printed. Or we could use read A B C... <<<$line to extract single data fields from each line and wholly reorganize the output as we want. Of course, there exists more efficient ways of doing this, maybe with awk, etc. Caveat: Even if rclone unbuffer its output, could be necessary to do that for stdin/stdout on the while command to guarantee a timely redrawing - I didn't make any tests.

I recommend grouping the commands in a script, say rclone.format.sh, to simplify the calling and debugging: rclone sync "src" "dst" | ./rclone.format

#!/bin/bash # formatting rclone progress output # use: rclone [options] | rclone.format.sh #-------------------- TXTPFIX="my customized progress text" while read LINE ; do if echo "$LINE" | grep -iq transferred ; then #-- erase screen on first line detected clear fi #-- send modified line echo "$TXTPFIX $LINE" done #-- end --# 

Don't forget chmod u+x rclone.format.sh to permit simple script execution.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.