From c84c00e12039113e2616f7835f338558762a5914 Mon Sep 17 00:00:00 2001 From: Tom Hendrikx Date: Fri, 5 Jul 2024 01:25:55 +0200 Subject: [PATCH] Fix some minor posix shell scripting issues --- test_config_syntax.sh | 4 ++-- test_grok_patterns.sh | 2 +- test_pipeline.sh | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test_config_syntax.sh b/test_config_syntax.sh index a48c9c0..86a2bca 100755 --- a/test_config_syntax.sh +++ b/test_config_syntax.sh @@ -3,7 +3,7 @@ set -eux docker run --rm -it \ - --volume $(pwd)/postfix.grok:/etc/logstash/patterns.d/postfix.grok \ - --volume $(pwd)/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \ + --volume "$(pwd)"/postfix.grok:/etc/logstash/patterns.d/postfix.grok \ + --volume "$(pwd)"/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \ logstash:8.12.0 \ logstash --config.test_and_exit -f /usr/share/logstash/pipeline/50-filter-postfix.conf diff --git a/test_grok_patterns.sh b/test_grok_patterns.sh index 08b1280..9978c83 100755 --- a/test_grok_patterns.sh +++ b/test_grok_patterns.sh @@ -12,4 +12,4 @@ FROM ruby:slim RUN gem install jls-grok minitest EOF -docker run --volume $(pwd):"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb" +docker run --volume "$(pwd)":"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb" diff --git a/test_pipeline.sh b/test_pipeline.sh index 338c4a6..573dde5 100755 --- a/test_pipeline.sh +++ b/test_pipeline.sh @@ -7,10 +7,10 @@ OUTPUT=$(mktemp tmp.logstash.out.XXXXX) PIPELINE=$(mktemp tmp.logstash.pipeline.XXXXX) echo Preparing input data -echo "postfix/smtp[123]: 7EE668039: to=, relay=127.0.0.1[127.0.0.1]:2525, delay=3.6, delays=0.2/0.02/0.04/3.3, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 153053D)" > $INPUT +echo "postfix/smtp[123]: 7EE668039: to=, relay=127.0.0.1[127.0.0.1]:2525, delay=3.6, delays=0.2/0.02/0.04/3.3, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 153053D)" > "$INPUT" echo Preparing pipeline config -cat > $PIPELINE << EOF +cat > "$PIPELINE" << EOF input { file { path => "/tmp/logstash.in" @@ -26,9 +26,9 @@ filter { } EOF -cat 50-filter-postfix.conf >> $PIPELINE +cat 50-filter-postfix.conf >> "$PIPELINE" -cat >> $PIPELINE << EOF +cat >> "$PIPELINE" << EOF output { file { path => "/tmp/logstash.out" @@ -38,32 +38,32 @@ EOF echo Starting logstash docker container CONTAINER_ID=$(docker run --rm --detach \ - --volume ./${INPUT}:/tmp/logstash.in \ - --volume ./${OUTPUT}:/tmp/logstash.out \ + --volume ./"${INPUT}":/tmp/logstash.in \ + --volume ./"${OUTPUT}":/tmp/logstash.out \ --volume ./postfix.grok:/etc/logstash/patterns.d/postfix.grok \ - --volume ./${PIPELINE}:/usr/share/logstash/pipeline/pipeline.conf \ + --volume ./"${PIPELINE}":/usr/share/logstash/pipeline/pipeline.conf \ logstash:8.12.0 \ logstash -f /usr/share/logstash/pipeline/pipeline.conf) -echo -n "Waiting for output from logstash " -until test -s $OUTPUT; do - echo -n "." +printf "Waiting for output from logstash " +until test -s "$OUTPUT"; do + printf "." sleep 2 done echo -docker stop --time 1 $CONTAINER_ID > /dev/null +docker stop --time 1 "$CONTAINER_ID" > /dev/null -if test "$(jq .tags[0] $OUTPUT)" = '"_grok_postfix_success"'; then +if test "$(jq .tags[0] "$OUTPUT")" = '"_grok_postfix_success"'; then echo Grok processing successful! - jq . $OUTPUT + jq . "$OUTPUT" else echo "Grok processing failed :<" - jq . $OUTPUT + jq . "$OUTPUT" exit 1 fi echo Cleaning up -rm -f $INPUT $OUTPUT $PIPELINE +rm -f "$INPUT" "$OUTPUT" "$PIPELINE" -echo Done \ No newline at end of file +echo Done