The HMC provides the "viosvrcmd" command to run VIO commands from the HMC.
Here are a couple of reasons you might want to do this:
- If you are building a LPAR from the HMC command line you can throw the commands in there to map VSCSI disks, create SSP LUN's, or map VFC adapters all right from the HMC command line.
- If you have SSH keys setup to your HMC, but not to each of your VIO's, you can use the SSH keys to connect to your HMC and run the viosvrcmd to connect to the VIO servers. This enables you to run command on your VIO servers through a script without having to have SSH keys on the VIO servers themselves.
The syntax for the command is: viosvrcmd -m managedsystem
Here is an example:
hscroot@hmc1:~> viosvrcmd -m p520 -p vio1 -c "ioslevel"
The man page points out that the "command cannot contain the semicolon (;), greater than (>), or vertical bar (|) characters."
However, one thing you might frequently need to do is run a command and grep for a certain string. If you try this directly with the viosvrcmd command line it won't work due to the pipe character:
hscroot@hmc1:~> viosvrcmd -m p520 -p vio1 -c "lsmap -all | grep vhost3"
HSCL2970 The IOServer command has failed because of the following reason: ioscli lsmap -all | grep vhost3 contains illegal data: |.
However a easy workaround to this is to put the pipe and grep after the viosvrcmd line so that the pipe is run on the HMC and not on the VIO. The end result is the same but you avoid putting a pipe in the command to be run on the VIO server so it works:
hscroot@hmc1:~> viosvrcmd -m p520 -p vio1 -c "lsmap -all" | grep vhost3
vhost3 U9111.520.1000000-V2-C12 0x00000005
Notice the the difference in where the closing quotation mark is; this makes all the difference. Before the pipe was in the quotes so it would have been sent to the VIO server which isn't allowed. In the next example the pipe is after the quote so it is run on the HMC server.
Running oem_setup_env commands through viosvrcmd
Dave pointed out in a comment on this article below that you can also run oem_setup_env commands through viosvrcmd if you put a line break in the middle of the command after the "oem_setup_env" and then type the command you want to run as root on the next line followed by a closing quote. In the next couple of examples we will run "whoami" through oem_setup_env just as an example to show the command is being run as root.
hscroot@hmc1:~> viosvrcmd -m p520 -p vio1 -c "oem_setup_env
I did some experimenting with this and also found you can do something like this which might be a little easier if you are scripting and want to make it easier to put the newline in the command:
hscroot@hmc1:~> command=`printf "oem_setup_env\nwhoami"`
hscroot@hmc1:~> viosvrcmd -m p520 -p vio1 -c "$command"
My new custom homemade AIX drink coaster:
Also, a fun little something I wanted to share.. My kids wanted to make some Perler Bead crafts this weekend. For those of you who aren't familiar with these they are little plastic pieces you arrange on a grid, and then iron them to melt them together.
My kids made cool Halloween characters, and of course I tried to think of something geeky to make.. Here is what I came up with: