What is the stderr that you get?
Here is a script that does something similar using telnet. I'm sure you can modify it to use ssh.
proc_sendcommands()
{
# Change host details here
rt_host=$1
rt_username=$USERNAME
rt_password=$PASSWORD
rt_command_0="sh conf"
rt_command_1="sh hardware"
rt_command_2=""
rt_command_3=""
rt_command_4=""
rt_command_5=""
rt_command_6=""
rt_command_7=""
rt_command_8=""
rt_command_9=""
rt_command_10=""
rt_command_11=""
rt_command_12=""
rt_command_13=""
rt_command_14=""
(sleep 3; echo $rt_username; sleep 3; echo $rt_password; sleep 1;echo $rt_command_0;sleep 1;echo $rt_command_1;sleep 1;echo $rt_command_2;sleep 1;echo $rt_command_3;sleep 1; echo $rt_command_4;sleep 1; echo $rt_command_5;sleep 1; echo $rt_command_6;sleep 1; echo $rt_command_7;echo $rt_command_8;sleep 1;echo $rt_command_9;sleep 1;echo $rt_command_10;sleep 1;echo $rt_command_11;sleep 1;echo $rt_command_12;sleep 1;echo $rt_command_13;sleep 1;echo $rt_command_14;sleep 10; echo "exit" ) | telnet $rt_host
}
#-----------------------------------------------------------------------------
# Main
IP_LIST=$1
USERNAME=cisco
PASSWORD=cisco
cat $IP_LIST | while read IP
do
echo Processing $IP
proc_sendcommands $IP
# Execute and send results to a file
# proc_sendcommands $IP > $IP.cfg
done