I am trying to get a list of only the names of gitlab runners.
So the output of gitlab-runner list 2>&1
is:
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
default_runner Executor=shell Token=251cda361f983e612b27381e2f73ad URL=http://10.6.20.230
test runner Executor=shell Token=86ab70918fc87c8a8d3a57c21457fb URL=http://10.6.20.230
Note that the names of the runners can contain spaces in them.
So I've tried the following:
gitlab-runner list 2>&1 | awk -F'Executor' '{if(NR>1)print $1}'
which gives me pretty much what I want (except with trailing spaces that I'll need to remove).
default_runner
test runner
However, if I change the field separator to Executor=
in hopes of making it more explicit, it no longer works. It returns the entire line.
$ gitlab-runner list 2>&1 | awk -F'Executor=' '{if(NR>1)print $1}'
default_runner Executor=shell Token=251cda361f983e612b27381e2f73ad URL=http://10.6.20.230
test runner Executor=shell Token=86ab70918fc87c8a8d3a57c21457fb URL=http://10.6.20.230
I've tried escaping it with Executor\=
to no avail. How can I include the equal sign in my split?
Edit:
It works if I take one of the lines and echo it into awk
$ echo "test runner Executor=shell Token=86ab70918fc87c8a8d3a57c21457fb URL=http://10.6.20.230" | awk -F'Executor=' '{print $1}'
test runner
Another thing to note is that, for whatever reason, gitlab-runner list
prints to stderr. That is why I redirect to stdout before I pipe to awk. Maybe I'm not redirecting properly? But that doesn't really make sense since awk picks it up without equal sign.