gcloud & gsutil stdout

1,520 views
Skip to first unread message

Ronald Bergmann

unread,
May 12, 2021, 11:30:33 AM5/12/21
to Google Cloud Developers

Hey,

I'm puzzled.
I do gcloud sql export sql ... --verbosity=error > /dev/null and then a gsutil cp ... > /dev/null in a script but
I still receive output like:

Exporting Cloud SQL instance...
.....done.

...
Copying gs:// ...
/ [0 files][    0.0 B/ 62.3 MiB]                                               
-
- [1 files][ 62.3 MiB/ 62.3 MiB]                                               
\
Operation completed over 1 objects/62.3 MiB.    
           

But why? Do they write their info output to stderr or am I missing something?   

Chris Gerber

unread,
May 12, 2021, 3:48:39 PM5/12/21
to Ronald Bergmann, Google Cloud Developers
The short answer is yes. Google CLI tools follow the POSIX standard of using stdout for conventional output and stderr for diagnostic output. The conventional output should be suitable for parsing by downstream tools, while the diagnostic output is not guaranteed to be consistent between versions and should not be relied on. You should be able to redirect stderr to /dev/null as well. If you are using Bash you would add `2>/dev/null`to your command.

--
You received this message because you are subscribed to the Google Groups "Google Cloud Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-dev/163adf93-9d38-4a44-b95e-bb4e3ed20eb5n%40googlegroups.com.

Ronald Bergmann

unread,
May 13, 2021, 2:28:50 AM5/13/21
to Google Cloud Developers
Thanks for the quick reply.

How come? I expect only errors to go to stderr, especially when I say --verbosity=error... output to stderr triggers an alert in our system. So I'll have to wrap the invocation, redirect everything to a file and only echo it if the exit code is non-zero, eh? Do you see any other solution? Of course I don't want the script to be completely silent, I need to know when it failed.

Best,
Ronald

C.J. Collier

unread,
May 13, 2021, 12:40:15 PM5/13/21
to Ronald Bergmann, Google Cloud Developers
Don't throw errors on receipt of data written to stderr.  Diagnostic output printed to file handle 2 is a normal part of a running program.

To get around your bug, you can print your stdout and stderr to separate logfiles:

gcloud sql export sql ... --verbosity=error > /tmp/gcloud.log 2>/tmp/gcloud.err

But really, consider fixing your bug that throws errors on logging.



Ronald Bergmann

unread,
May 17, 2021, 4:12:02 AM5/17/21
to Google Cloud Developers
Aight, I'll trap the outputs
Reply all
Reply to author
Forward
0 new messages