run a application from a remote server via script?

I have a ksh script that does a bunch of things, then runs

telnet server_b

I then manually login, manually run one command (which launches an application with display back to my workstation), then logout at which point the main script takes back over, runs something else, then ends.

Is there anyway to automate the manual parts?

Have you tried a here document?

telnet somenode<<EOF
username
password
special_command
exit
EOF

Jim,

What is a here document?

Also, that solution does not work, just tosses me back out to my orig host.

you should really look into using "expect", but here's a 'poor-man' attempt to do it with the 'pipped' "telnet":

#!/bin/ksh

host='myHost'
user='anyUserName'
pass='aPassword'

    (
    sleep 3
    print "${user}"
    sleep 1
    print "${pass}"
    sleep 2
    print "ls ~"
    sleep 1
    print "exit"
    sleep 3
    ) | telnet "${host}"

Thanks vgersh99,

Looks somewhat like sendkeys (VBA command). I looked up expect. Looks like I'll need to play with it a lot before getting it to work, but undoubtedly a better approach.

Thanks for the help.