I
I
Ivan2019-03-26 10:08:44
linux
Ivan, 2019-03-26 10:08:44

How to replace the name of all containers with their ip in a loop?

There are containers

CTID      NPROC STATUS    IP_ADDR         HOSTNAME
       101         19 running   127.0.0.2       test1
       102         19 running   127.0.0.3       test2

You need to assign hostname .= ip of the container.
You can do it manually in the form:
vzctl set 101 --hostname "127.0.0.2" --save
I select the required fields, these are id and ip, but this is already a string, how to separate it during the cycle?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2019-03-26
@ky0

awk '{print $1, $4}'

S
SunTechnik, 2019-03-26
@SunTechnik

For example, through a temporary file.
vzlist -H -o ctid | awk ' { print "vzctl set " $1 , " --hostname \"" $4 "\" --save" }' > /tmp/cmd
Check what happened in /tmp/cmd
If everything is fine, then execute it:
sh /tmp/cmd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question