0

I have the following bash script:

#!/bin/bash
KEY=$(./get-aws-profile.sh --profile=$1 --key)
SECRET=$(./get-aws-profile.sh --profile=$1 --secret)
ES="https://search-****.eu-west-1.es.amazonaws.com"
INDEXES=$(AWS_ACCESS_KEY_ID="$KEY" AWS_SECRET_ACCESS_KEY="$SECRET" aws-es-curl $ES/_cat/indices | awk '{print $3}')
YESTERDAY=$(date --date="yesterday" +"%Y.%m.%d")

for i in $INDEXES
do
   # $i is like report-processing-2019.10.10
   if grep "$YESTERDAY" $i; then
      echo "Pulling documents from $i to $i.ndjson"
      echo "docker run -it blaze blaze --host=$ES --index=$i  --insecure > /tmp/$i.ndjson"
      echo "Index $i saved"
   else
      echo no
   fi
done

exit 0

where $i is like report-processing-2019.10.10

when i run this, i am not able to get the the lines which contain only lines with 2019.10.10 in them, what am i missing?

any advice is much appreciated

3
  • 1
    see associated Q&As regarding pattern matching: check for substring, pattern matching, regex match Commented Oct 11, 2019 at 14:13
  • You can use the match operator: if [[ $YESTERDAY =~ $i ]]; then do something. Commented Oct 11, 2019 at 14:25
  • thanks, if [[ $i =~ $YESTERDAY ]]; then do something worked Commented Oct 11, 2019 at 14:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.