Saturday 11 October 2014

Run VIO commands from the HMC using "viosvrcmd" without VIOs Passwords

Recently  we got a situation where  in we don't know the passwords of  either padmin/root of VIOS  but need to run commands in VIOs.

Found an interesting command  in HMC  called "viosvrcmd",which will enble us to run commands on VIOs through HMC.
viosvrcmd -m managed-system {-p partition-name | --id partition-ID} -c "command" [--help]
Description: viosvrcmd issues an I/O server command line interface (ioscli) command to a virtual I/O server partition.

The ioscli commands are passed from the Hardware Management Console (HMC) to the virtual I/O server partition over an RMC session.

RMC does not allow interactive execution of ioscli commands.
-m    VIOs managed system name

-p    VIOs hostname

--id  The partion ID of the VIOs

Note:You must either use this option to specify the ID of the partition, or use the  -p option to specify the partition's name. The --id and the -p options are mutually exclusive.

-c    The I/O server command line interface (ioscli) command to issue to the virtual I/O      server partition.

Note: Command must be enclosed in double quotes. Also, command cannot contain the      semicolon (;), greater than (>), or vertical bar (|) characters.

--help  Display the help text for this command and exit.
Here is an example:
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "ioslevel"
2.2.0.0
Since  we can't give the ; or > or |  in the command , if you need to process the output using filters , you can use that after "".
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "lsdev -virtual" | grep vfchost0
vfchost0         Available   Virtual FC Server Adapter

What if  you want to run  command as root (oem_setup_env) ,  

got a method from internet
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env
> whoami"
root

You can  run in one shot like below

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env\n whoami"
root
If you need to run multiple commands , you can use them by assiging the commands to a variable and call the variable in place of the command parameter.
hscroot@umhmc:~>command=`printf  "oem_setup_env\nchsec -f /etc/security/lastlog -a unsuccessful_login_count=0 -s padmin"`

hscroot@umhmc:~>viosvrcmd -m umfrm570 -p umvio1 -c "$command"

0 blogger-disqus:

Post a Comment