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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .buildkite/scripts/tooling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ upload_safe_logs() {
local source="$2"
local target="$3"

if ! ls ${source} 2>&1 > /dev/null ; then
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
if ! ls ${source} > /dev/null 2>&1; then
echo "upload_safe_logs: artifacts files not found at ${source}, nothing will be archived"
Comment on lines +104 to +105
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

return
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f -u elastic:changeme "https://elasticsearch:9200/_cat/indices/.security-*?h=health" | grep -v red
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ services:
kibana:
condition: service_healthy
healthcheck:
test: "curl --cacert /etc/ssl/elastic-agent/ca-cert.pem -f https://localhost:8220/api/status | grep -i healthy 2>&1 >/dev/null"
test: "curl --cacert /etc/ssl/elastic-agent/ca-cert.pem -f https://localhost:8220/api/status | grep -i healthy >/dev/null"
start_period: 60s
interval: 5s
hostname: docker-fleet-server
Expand Down
2 changes: 1 addition & 1 deletion internal/stack/_static/fleet-server-healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NUMBER_SUCCESSES="$1"
WAITING_TIME="$2"

healthcheck() {
curl -s --cacert /etc/ssl/certs/elastic-package.pem -f https://localhost:8220/api/status | grep -i healthy 2>&1 >/dev/null
curl -s --cacert /etc/ssl/certs/elastic-package.pem -f https://localhost:8220/api/status | grep -i healthy >/dev/null
}

# Fleet Server can restart after announcing to be healthy, agents connecting during this restart will
Expand Down
2 changes: 1 addition & 1 deletion internal/stack/_static/kibana-healthcheck.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f -u {{ fact "username" }}:{{ fact "password" }} "https://elasticsearch:9200/_cat/indices/.security-*?h=health" | grep -v red