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

khinester
  • 3,398
  • 9
  • 45
  • 88
  • 1
    see associated Q&As regarding pattern matching: [check for substring](https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash), [pattern matching](https://stackoverflow.com/questions/44688460/bash-script-pattern-matching), [regex match](https://stackoverflow.com/questions/9289239/regex-match-bash-variable) – markp-fuso Oct 11 '19 at 14:13
  • You can use the match operator: ```if [[ $YESTERDAY =~ $i ]]; then do something```. – accdias Oct 11 '19 at 14:25
  • thanks, `if [[ $i =~ $YESTERDAY ]]; then do something` worked – khinester Oct 11 '19 at 14:54

0 Answers0