Bash script + expect

im very happy to back for this forum

I have servers with alias of double dns extentions:
sample:
servera.test.com
servera.test1.com

serverb.test.com
serverb.test1.com

I need to login to that severs and executing the set of commands

if test.com failed then try to login via test1.com

i'l create a bash script with expect and spawn but the issue is I cant able to do the if , else for giving the hostname with dns alias.

if anyone known, please help me on this ,after long and many years im starting my script knowledge.

thanks in advance.