0

In bash I got all the names from services which are balanced from /etc/haproxy. But now I want to store all these intro a $srv variable in order to continue my healthcheck script.

for filename in /etc/haproxy/*.cfg; do
    for ((i=0; i<=0; i++)); do
      srv = $(echo $filename | awk -F'[/.]' '{print $4}')
      echo $srv
    done
done

Using echo $filename | awk -F'[/.]' '{print $4}' is showing the correct microservices names like: service1 service2 service3

2
  • 1
    No spaces around the = in shell assignments. Commented Aug 1, 2016 at 9:25
  • Change line-3: to srv="$(echo "$filename" | awk -F'[/.]' '{print $4}')" Commented Aug 1, 2016 at 9:27

1 Answer 1

2

You can't have spaces around the = in shell variable assignments. What you wrote is trying to run the srv command, not assign to the srv variable. It should be:

srv=$(echo $filename | awk -F'[/.]' '{print $4}')
Sign up to request clarification or add additional context in comments.

2 Comments

How do you learn shell scripting without such basic information?
I use only chef and ruby. But apparently there are VMs were you cannot set ruby environments and you have to deal with bash:) Last time I got blocked at the exact same step but I found a way around with some percona healthchecks. Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.