SSH Script

So, right now I'm trying to make an SSH script for my place of employment. This script, I want to go out to the server hostnames we have specified (in another file) and change a users account password. We use Kerberized telnet, so if telnet root hostname fails, I want it to use ssh username[at]hostname and use the old password (specified). If both fail, I want it to ask the user what the port should be and input the port in the ssh command.

But I'm having a issue having it try telnet root hostname and if it fails then, try to ssh in, I have no clue how to have it proceed. Is it an if statement?

Here's the telnet failed message:
telnet: Unable to connect to remote host: Connection refused

So if it sees refused, then it goes to ssh (maybe?)

Thanks!!

I'm not sure I follow what you're saying. If you want to check if the last command worked or not, you need to look at it's exit status $?. Usually 0 is succeeded, and 1 is it failed (but some programs have more than just that). So what it looks like you're trying to do is:

somecommand
if [[$? -eq 1 ]];then 
      command_in_the_event_of_failure
else
      command_in_the_event_of_success
fi