0

I want to parse the content of the HAProxy status socket so its less noisy. I wrote the following bash script:

#!/bin/sh

while IFS=, read -r pxname svname qcur qmax scur smax slim stot bin bout dreq dresp ereq econ eresp wretr wredis status weight act bck chkfail chkdown lastchg downtime qlimit pid iid sid throttle lbtot tracked type rate rate_lim rate_max check_status check_code check_duration hrsp_1xx hrsp_2xx hrsp_3xx hrsp_4xx hrsp_5xx hrsp_other hanafail req_rate req_rate_max req_tot cli_abrt srv_abrt comp_in comp_out comp_byp comp_rsp lastsess last_chk last_agt qtime ctime rtime ttime; do
    [[ "$pxname" != "# pxname" ]] && echo "$pxname $svname $status"
done < <(echo "show stat" | socat stdio /var/run/haproxy.sock | sort)

When I execute it, I get the following error:

line 5: syntax error near unexpected token `<'

While I'm not a bash expert, my understanding of process substitution is that I can use it anywhere I normally can use a file. Indeed replacing <(....) with haproxy.csv works as expected. haproxy.csv in this case is the output of echo "show stat" | socat stdio /var/run/haproxy.sock | sort

How do I read the output of the commands within the parenthesis and process them in a loop?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Jason Thompson
  • 4,643
  • 5
  • 50
  • 74

0 Answers0