Skip to content

Update stderr redirections in scripts #2819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Aug 12, 2025

This PR updates the scripts or commands that redirect stderr to stdout.
For instance, this command does not redirect stderr to stdout as expected, it keeps showing the stderr:

 $ ls doesnotexist 2>&1 > /dev/null
ls: cannot access 'doesnotexist': No such file or directory

That command should be written as:

 $ ls doesnotexit > /dev/null 2>&1

@mrodm mrodm self-assigned this Aug 12, 2025
@@ -2,5 +2,5 @@

set -e

curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login | grep kbn-injected-metadata 2>&1 >/dev/null
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login | grep kbn-injected-metadata >/dev/null
Copy link
Contributor Author

@mrodm mrodm Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in these commands it is not needed to use 2>&1, since curl has the silent parameter (-s).

In case it is required, I think in one of these ways:

# redirect the stderr to stdout in the command before pipe
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login 2>&1 | grep kbn-injected-metadata > /dev/null

# pipe both stdout and stderr to the stdin of the next command (same as before)
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login |& grep kbn-injected-metadata > /dev/null

# using a subshell to run the command
(curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login | grep kbn-injected-metadata) > /dev/null 2>&1

@elasticmachine
Copy link
Collaborator

elasticmachine commented Aug 12, 2025

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @mrodm

Comment on lines +104 to +105
if ! ls ${source} > /dev/null 2>&1; then
echo "upload_safe_logs: artifacts files not found at ${source}, nothing will be archived"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid showing the stderr output like:

ls: cannot access 'build/elastic-stack-dump/check-httpjson_false_positive_asserts/logs/elastic-agent-internal/default/*': No such file or directory
upload_safe_logs: artifacts files not found, nothing will be archived

And instead show this message:

upload_safe_logs: artifacts files not found at build/elastic-stack-dump/check-httpjson_false_positive_asserts/logs/elastic-agent-internal/default/*, nothing will be archived

@mrodm mrodm marked this pull request as ready for review August 12, 2025 19:22
@mrodm mrodm requested a review from a team as a code owner August 12, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants