Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Can't parse gdrive stdout output propely in shell script #661

Closed
fritzrehde opened this issue Nov 17, 2022 · 1 comment
Closed

Can't parse gdrive stdout output propely in shell script #661

fritzrehde opened this issue Nov 17, 2022 · 1 comment

Comments

@fritzrehde
Copy link

I want to parse the output of the upload command line by line with a while loop in a shell script. However, gdrive doesn't print new updates (e.g. updated progress percentage) to new lines on stdout, I think it uses \r to remove the last line so it looks like there is only one output line that is constantly getting updated.
I am trying to convert all \rs into \ns with this script, but it isn't working. It keeps printing the gdrive output instead of the inside of the while loop.

gdrive upload "$FILE" \
	| tr '\r' '\n' \
	| while read LINE; do 
	echo "do something with: $LINE"
done

Any ideas how to fix this script (or is this a bug in gdrive)?

@fritzrehde
Copy link
Author

I found the issue: gdrive prints to stderr instead of stdout. So this is what works for now:

stdbuf -oL gdrive upload "$FILE" 2>&1 \
	| stdbuf -i0 -oL tr '\r' '\n' \
	| grep --line-buffered '[^[:blank:]]' \
	| while read LINE; do 
	echo "do something with: $LINE"
done;

But this is still quite complicated, so I'll file another issue for better logging output.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant