I would go for 2 part solution. One part is the expect script, the other part is the Shell script.
For the expect script, it should be a generic script that accept input, and produce output.
This is my example expect script that accept hostname and password, and will produce the vcprofile name for the server
[user@server ~]$ cat getvcprofile.expect
#!/usr/bin/expect
set timeout 2
set host [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh "ADMIN\@$host"
expect_after eof { exit 0 }
expect "yes/no" { send "yes\r" }
expect "assword" { send "$password\r" }
expect "oa>" { send "show vcmode\r" }
expect "oa>" { send "exit\r" }
exit
In the shell script, I will call the expect script and providing it with the variable, in this case the hostname for vcsystem. The password is actually a pattern according to the hostname OA@XXXX - where the XXXX is the last 4 digit number of the server
[user@server ~]$ cat getvcprofile.sh
#/bin/bash
# get VC profile for a host
host=$1
#get the blade enclosure
enclosure=`callsub -enc $host |grep Enclosure: | cut -d" " -f2`
if [ ! -z $enclosure ]; then
#get the last 4 digit of the enclosure
fourdigit=${enclosure: -4}
domain=`./getvcprofile.expect ${enclosure}oa OA@${fourdigit} |grep Domain|awk '{print $NF}'`
echo $domain
else
echo "None"
fi
With this 2 part solution, I can do something like this:
for X in `cat serverlist.txt`; do echo -n $X": "; ./getvcprofile.sh $X; done
And it will print out the vcprofile for each of the servers in the file serverlist.txt