script for nested rlogin and telnet

I want to write a script that rlogins to a couple machines and then from the last machine, telnet into a final machine and execute a command. So in pseudocode it would look like:

rlogin host1
from host1 rlogin host2
from host2 telnet host3
from host 3 execute command

The reason for the nesting of the logins/telnet is because host 3 is only available via a telnet from host 2 and host 2 is only available via host 1.

Any ideas on how to accomplish this?? Thanks.

Just a matter of nesting the subshells.
It depends heavily on the exact shell you'd use at each level but something like this:

rlogin host1 (rlogin host2 (rlogin host 3 (command)))

or

rlogin host1 rlogin host2 rlogin host3 command

Alternativly, try substituting quotes in place of brackets if the shell doesn't like your syntax.

edit: Oh wait, your need to use telnet on the last hop...
For that, you'll need a .netrc file on host2 pipe into the telnet rather than provide the command as a parameter.

Thanks for the help, but it did not work. I'm trying to get this working piece by piece and am just focusing on rloging into host1 and then from host1 rloging into host2 and cannot get this to work. I've tried:

rlogin host1 (rlogin host2)

rlogin host1 'rlogin host2'

rlogin host1 "rlogin host2"

And it keeps complaining about the rlogin syntax. Any other ideas out there?

Ah, my bad, I was thinking of rsh. Is that an option for you?

I've made some progress. So far I can remsh into host1, then from host1 I can remsh into host2, and then from host2 I can telnet into host3 with this script:

#! /bin/csh

remsh host1 "remsh host2 "telnet host3""

The final hurdle I need to get over is executing a command on host3. I've tried:

remsh host1 "remsh host2 "echo 'command' | telnet host3""

But that didn't even seem to telnet me into host3, I got an error saying "no route to host". If I manually rlogin into host1 and then from there manually log into host2 and execute the command "echo 'command' | telnet host3" it works just as I'd like. I don't get why it can't do it via a script.

It's your quoting, the telnet is trying to run back on host1, it's not getting passed to host 2 as a commandline parameter due to the pipe not being properly escaped into a subshell.

Have a go with " \" ' and ( some more to find what you need to protect the | better.

Wasap guys, kind of the same situation,
how can I design a script to nest to another server and type the user id and password for me.
Ive tried

rlogin HOST |&
sleep $DELAY
print -p $USER
sleep $DELAY--------> 2 sec
print -p UPASS

and Ive tried
rlogin host -l <user>
and it takes me to the server but still asks for the password.

we dont have ssh installed