With the expect command maybe?
http://www.thegeekstuff.com/2010/12/5-expect-script-command-line-argument-examples/
Here is a little example with FTP since I am not familiar with mdadm. You can see it does something different depending on the response from the server - which is, I think, what you are trying to do.
# Connect to the FTP server using the "spawn" command.
spawn ftp $hostname
# Wait for a login prompt.
expect -re "(Name|login|Login|Username).*:.*" {
# Login prompt received. Send username to server.
exp_send "$username\r"
exp_send_user "sent username\n"
} eof {
# No login prompt received. Display an error.
exp_send_user "could not connect\n"
}