Thursday 14 March 2013

How to run remote command on VIO server


This article explain How to run remote command on VIO server . Few days back , I came across a situation where I had to check IBM Virtual I/O server version ( ioslevel ) on more than 200 servers. Then only I came to know that lot experienced people as well as myself do not know how to run command remotely on a Restricted Shell as we all know VIO server is supplied with Restricted Korn Shell and we login with primary administrator user id padmin .
Restricted shell : 
After logging in with padmin user id on a VIO server, you will be placed into a restricted Korn shell. The restricted Korn shell works in the same way as a standard Korn shell, except that you cannot perform the following:
  • Change the current working directory
  • Set the value of the SHELL, ENV, or PATH variables
  • Specify the path name of the command that contains a forward slash (/)
  • Redirect output of a command using any of the following characters: >, >|, <>, >>
As a result of these restrictions, you cannot execute commands that are not accessible to your PATH variables. In addition, these restrictions prevent you from sending command output directly to a file. Instead, command output can be piped to the tee command.
Work Around :
Secure Shell (SSH) is shipped with the Virtual I/O Server. Hence, scripts and commands can run remotely after an exchange of SSH keys .
Step 1 ) Generate the public ssh key on the remote system. To know how to generate ssh key in details, please visit my earlier article SSH to a server without password for Admin Ease
Step 2 ) Transfer the ssh key to the Virtual I/O Server. The transfer can be done using File Transfer Protocol (FTP).
Step 3 ) On the Virtual I/O Server, type the following command to copy the public key to the .ssh directory:
$ cat id_rsa.pub >> .ssh/authorized_keys2
Step 4) Run any command from remote server with ioscli flag as below example . The command might prompts for a password for first time if it has not already been added as a known host.
Example :
ssh padmin@VIO1 ioscli ioslevel
2.2.1.4
Then I have wrote a script vioversion.sh on our NIM server to ran remotely above command on more 200 servers and my work was finished in 10 mins .. and rest of the day I was free to roam
$cat /tmp/vioversion/vioversion.sh
#!/bin/ksh
echo;
echo “Input the VIO server list :
read input
for i in `cat /tmp/vioversion/$input`
do
echo “————————————————————————–”
echo ” IOSLEVEL on VIO $i ”
ssh padmin@$i ioscli ioslevel > /tmp/vioversion/vioversion.out
echo “————————————————————————–”
done
This script will put the out put in a file with name vioversion.out under /tmp/vioversion/.. Have fun and  run remote command on VIO server!!!

No comments:

Post a Comment