As in the cycle to replace the name of all containers on their ip?

There are containers
 101 19 running test1
 102 19 running test2

You need to assign a hostname .= the ip of the container
You can make your hands in the form :
vzctl set 101 --hostname "" --save

Choose the required field is id and ip, but this is the line, how to separate while loop?
March 19th 20 at 08:36
2 answers
March 19th 20 at 08:38
awk '{print $1, $4}'
I probably do not say so
you can choose a -o ctid,ip
the point is how to use them in a loop for each of the next id to assign his ip to hostname
for CT in $(vzlist -H -o ctid); do echo "== CT $CT =="; vzctl exec $CT uptime; done
Only use id, and need id + ip - jana95 commented on March 19th 20 at 08:41
@jana95, then it is not clear what the difficulty is. Sorted turns of line in a loop, adding the data you need into variables and then performing the desired command. This can be done easily in bash with a combination of IFS and read.$IFS - Jaleel_Glover29 commented on March 19th 20 at 08:44
March 19th 20 at 08:40
For example, using a temporary file.
vzlist -H -o ctid | awk ' { print "vzctl set" $1 , " --hostname \"" $4 "\" --save" }' > /tmp/cmd
Check out what happened in the /tmp/cmd
If all goes well, then execute it:
sh /tmp/cmd

Find more questions by tags OpenVZLinux