Scripting directly within the HMC restricted shell - It can be done!
brian_s 270002K5X3 Comments (2) Visits (11832)
I've always wanted to be able to write and run scripts directly on the HMC instead of having to setup SSH keys and run scripts from another server. Using the SSH keys from another server is OK, but it adds complexity, and can really slow things down if you need to run a lot of HMC commands (for example when iterating over every LPAR in every frame and running multiple commands per LPAR). Also, at some companies it might be difficult to get permission to setup SSH keys for the HMC.
I've found a method that allows you to write and run scripts directly on the HMC, and it is all within the HMC restricted shell and using only HMC supported commands.
To write and edit the scripts, use the "rnvi -f" HMC command (for example "rnvi -f testscript"). This will open a vi editor that allows you to create or edit any file in your home directory. Don't be alarmed if you see messages from rnvi about "Error: stderr: Bad file descriptor": according to the rnvi manual page this is normal.
Your script can run any HMC commands. Your script will still be in the restricted shell, but there is still quite a bit that you can do.
To run the script, use the "source" command. For example "source testscript". This will run the script in your current shell.
To test this method out, I created a quick example script using the command "rnvi -f testscript":
This example script loops through every managed system and every LPAR. For each LPAR it gets the CPU, Virtual CPU, and Memory settings from the profile and the OS version from lssyscfg. It then prints it out in a formatted output (this HMC only has 1 managed frame so the output is pretty brief):
If you are running HMC 184.108.40.206 SP1 or similar versions it looks like there might be a issue with the "rnvi" command. If you get a message "nvi: error while loading shared libraries: libdb-4.5.so: cannot open shared object file: No such file or directory" when you try using rnvi it is caused by a missing library in the directory rnvi chroots to. To fix: "cp /usr
If you like this, you might also be interested in my previous posting Easy console access from the HMC command line which uses this same method to create an alias that allows you to open a virtual console on LPAR's very easily from the HMC command line.