Answer the question
In order to leave comments, you need to log in
How to loop the result of a bash command?
There is a command that gives a list of Docker container names.
What is the correct way to write a loop in Bash?
How to substitute these names in a loop by executing another command?
Well, or maybe your options, the best ways to get the result of the team.
container=$(docker container ls --format 'table {{.Names}}');
while $container
do
docker exec -u root -it $container netstat -natu | grep -c ESTABLISHED;
done
Answer the question
In order to leave comments, you need to log in
To pass command output arguments as a single value, you need to have the correct output. Those. instead of
container=$(docker container ls --format 'table {{.Names}}')
gotta docontainer=$(docker container ls --format '{{.Names}}')
#!/bin/bash
container=$(docker container ls --format '{{.Names}}');
for i in $container
do
docker exec -u root -it $i netstat -natu | grep -c ESTABLISHED;
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question