-
Type: New Feature
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Shell
-
Service Arch
I wish there is a way on the mongo shell for redirecting the output to STDERR or files.
The current workaround is just adding some tags as boundaries and parsing the output from a bash script or another application.
... print("<STDOUT>") print(multiline_json) print("</STDOUT>") print("<STDERR>") print(multiline_json) print("</STDERR>") ...
And at the bash script side:
#!/bin/bash COMMAND="mongo <args>" OUTPUT=$(${COMMAND}) function STDERR { cat - 1>&2 } function STDFILE { if [ -z "$1" ]; then return fi cat - >> $1 } WRITE_ERR=0; for line in $OUTPUT; do if [[ "$line" == "<STDERR>"* ]]; then WRITE_ERR=1 continue elif [[ "$line" == "</STDERR>"* ]]; then WRITE_ERR=0 continue fi if [ "$WRITE_ERR" -eq "1" ]; then printf "%s\n" "$line" | STDERR else printf "%s\n" "$line" fi done
- is duplicated by
-
SERVER-27311 3.2.10 js client prints trace messages in output of js script
- Closed
- is related to
-
SERVER-19791 Save mongo shell session into a file (gdb style)
- Closed
- related to
-
SERVER-14880 Ability to output to file from mongo shell
- Backlog