Previous page

Next page

Locate page in Contents

Print this page

Running Commands in Container

Usually, a Container administrator logs in to the Container via network and executes any commands in the Container as on any other Linux box. However, you might need to execute commands inside Containers bypassing the normal login sequence. This can happen if:

The Virtuozzo Containers software allows you to execute commands in a Container in these cases. Use the vzctl exec <CT_ID> command for running a command inside the Container with the given ID. The session below illustrates the situation when the SSH daemon is not started:

# vzctl exec 101 /etc/init.d/sshd status

sshd is stopped

# vzctl exec 101 /etc/init.d/sshd start

Starting sshd:[ OK ]

# vzctl exec 101 /etc/init.d/sshd status

sshd (pid 26187) is running...

Now Container users can log in to the Container via SSH.

When executing commands inside a Container from shell scripts, use the vzctl exec2 command. It has the same syntax as vzctl exec but returns the exit code of the command being executed instead of the exit code of vzctl itself. You can check the exit code to find out whether the command has completed successfully.

If you wish to execute a command in all running Containers, you can use the following script:

# for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i <command>; done

where <command> is the command to be executed in all the running Containers. For example:

# for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i uptime; done

Container 1

2:26pm up 6 days, 1:28, 0 users, load average: 0.00, 0.00, 0.00

Container 101

2:26pm up 6 days, 1:39, 0 users, load average: 0.00, 0.00, 0.00

[The rest of the output is skipped...]

Please send us your feedback on this help page