Edit: I love revisiting these scripts, and I wonder if anyone still runs them.
Originally posted May 13, 2008 on AIXchange
I recently saw another great script from the mailing list, written by Dean Roswell. To get it working on my machine, I loaded these rpms from the AIX Toolbox CD:
tcl-8.4.7-3.aix5.1.ppc.rpm
tk-8.4.7-3.aix5.1.ppc.rpm
expect-5.42.1-3.aix5.1.ppc.rpm
Then I followed the instructions in the script’s introductory comments (seen in the script listed below) and set up the ssh keys to allow automatic login from my AIX machine to my VIO server. After editing the list of VIO servers in the script to match what I had in my environment, I was able to use this script to send out the same command to multiple VIO servers at the same time.
They gave some examples from the e-mail I saw.
Syntax:
root@coenim:/:# dshvio -?
Valid parameters are:
-r for a root command
-n for a list of VIO servers
-n vios1
-n vios1,vios2
A regular VIOS command:
root@coenim:/:# dshvio ioslevel
=========================
VIO server –> coevios1
=========================
1.5.1.1-FP-10.1
=========================
VIO server –> coevios2
=========================
1.5.1.1-FP-10.1
An example of running a command through oem_setup_env automatically:
dshvio -r fget_config -Av
=========================
VIO server –> coevios1
=========================
—dar0—
User array name = ‘COE-DS4700’
dac0 ACTIVE dac1 ACTIVE
Disk DAC LUN Logical Drive
hdisk2 dac1 0 coenim_nim
hdisk3 dac1 1 coesap01_disk1
=========================
VIO server –> coevios2
=========================
—dar0—
User array name = ‘COE-DS4700’
dac0 ACTIVE dac1 ACTIVE
Disk DAC LUN Logical Drive
hdisk2 dac1 0 coenim_nim
hdisk3 dac1 1 coesap01_disk1
And here’s a command that I ran in my environment:
./dshvio.ksh -r “lscfg | grep disk”
=========================
VIO server –> vios1
=========================
vios1:/home/padmin # oem_setup_env
+ hdisk0 U787F.001.DPM1XRD-P1-T10-L3-L0 16 Bit LVD SCSI
Disk Drive (73400 MB)
+ hdisk1 U787F.001.DPM1XRD-P1-T10-L4-L0 16 Bit LVD SCSI
Disk Drive (73400 MB)
+ hdisk2 U787F.001.DPM1XRD-P1-T10-L5-L0 16 Bit LVD SCSI
Disk Drive (73400 MB)
=========================
VIO server –> vios3
=========================
vios3:/home/padmin # oem_setup_env
* hdisk0 U787F.001.DPM1XRD-P1-C1-T1-W5005076801103022-L0
MPIO Other FC SCSI Disk Drive
* hdisk1
U787F.001.DPM1XRD-P1-C6-T1-W5005076801202FFF-L1000000000000 MPIO
Other FC SCSI Disk Drive
* hdisk2 U787F.001.DPM1XRD-P1-C6-T1-W5005076801202FFF-
MPIO Other FC SCSI Disk Drive
This means that I can run commands across all of my VIO servers from my AIX machine, in either the padmin or oem_setup_env environment when I specify the -r option. I welcome any changes or improvements that readers might suggest, and I hope that Dean continues to share these useful tools with us.
#!/bin/ksh
# Created by Dean Rowswell, IBM, April 26, 2006
# Modified by Dean Rowswell, IBM, October 11, 2007
# Added a check for the -r flag for a root user command
# NOTE: this flag will require the expect RPM package to be installed
# Modified by Dean Rowswell, IBM, October 12, 2007
# Added a check for the -n flag to specify a single or multiple VIO servers
#
#——————————————————————————
# Assumption: this server is a trusted host for running ssh commands to
# the VIO server(s)
# To set this up:
# ssh-keygen -t dsa (press ENTER for all prompts)
# scp $HOME/.ssh/id_dsa.pub padmin@VIOserver:.ssh/authorized_keys2
#
# NOTE: if the VIO server responds with “rksh: ioscli: not found” then
# login to the VIO server and change to the root shell via oem_setup_env.
# Edit /etc/ssh/sshd_config
# Change: PermitUserEnvironment no
# To: PermitUserEnvironment yes
# Run: stopsrc -s sshd ; startsrc -s sshd
#——————————————————————————
#===========================================================#
# Define the list of VIO servers in this variable
#===========================================================#
VIOS=”vios1 vios3″
#===========================================================#
DisplayUsage() {
echo “Syntax: dshvio COMMAND\n Run dshvio -? for the valid parameters”
exit
}
if [ ${#*} -eq 0 ]
then
DisplayUsage
else
while getopts :rn: PARMS
do
case $PARMS in
r) lslpp -L|grep -w expect >/dev/null
if [ $? -ne 0 ]
then
echo “ERROR: cannot use -r flag because expect\
RPM package is not installed”
exit 1
else
ROOT=1
fi ;;
n) VIOS=${OPTARG}
VIOS=`echo ${VIOS}|sed ‘s/,/ /g’`;;
?) echo “Valid parameters are:\n -r for a root command\n\
-n for a list of VIO servers\n -n vios1\n -n vios1,vios2″ ; exit ;;
esac
done
shift $(($OPTIND -1))
VIOSCMD=${*}
if [ ${#VIOSCMD} -eq 0 ]
then
DisplayUsage
fi
fi
for VIO in ${VIOS}
do
ping -c1 ${VIO} >/dev/null 2>/dev/null
if [ $? -eq 0 ]
then
echo “======================\nVIO server –> ${VIO}\n\
======================”
if [ ${ROOT:=0} -ne 1 ]
then
ssh padmin@${VIO} “ioscli ${VIOSCMD}”
else
expect -c “spawn ssh padmin@${VIO} ;expect \”\$\*\”;\
send \”oem_setup_env\\r\”;expect \”\#\*\”;send \”${VIOSCMD}\\r\”;\
send \”exit\\r\”;expect \”\$\*\”;send \”exit\\r\””|egrep -v “^spawn\
|^Last|oem_setup_env|^exit|^#”
fi
else
echo “===================\\nVIO server –> ${VIO}\n\
===================”
echo “VIO server: ${VIO} is not responding”
fi
done