how to close telnet from script dynamically

I'm running through ksh the following telent command, the script
date.ksh should run between 4 to 6,7 minutes.
and I don't want to put sleep of 400, etc.
I can put in the end of the date.ksh an echo "DONE" or something...
but how can I get or license and not close the telnet session untill
it ended.
it's important because after the telnet end a ftp command should bring
the out files of the date.ksh back.

I'm not sure that ksh is strong enough to do it, any other script way
is wellcome... thanks

( sleep 2
echo "$USER"
sleep 2
echo "$PASSWORD"
sleep 2
echo "cd $REMOTE_DIR"
sleep 2
echo "gunzip file.tar.gz"
sleep 8
echo "tar xvf file.tar"
sleep 8
echo "./date.ksh"
) | telnet $HOSTNAME | grep "[-.:A-Z0-9a-z]\{1,250\},[-.:A-Z0-9a-z]

Relevant Pages

  • Telnet from within a script strange problem
    ... I tried to send it to a debian server ... When try the same from a commandline, not a script, it works fine. ... echo "HELO" ...
  • Want to understand why this doesnt work right, please
    ... I cobbled together a very basic script to run a program, sleep, run ... The program does launch and run as desired. ... in the Echo to tell me when the script is completed. ...
  • Telnet script
    ... I need to telnet to an UNIX server with telnet and run a script ... (echo open $$ ...
  • Re: [SLE] How to spawn another shell script in separate process
    ... I would advise to look into your ip-up.local.doit script, ... Parent processes usually ... echo in before calling ... echo running sleep... ...
  • Re: Bash: how to make some conditions
    ... Then I have made a #!/bin/sh script that works on with these files. ... it should sleep(?) some time and try again. ... echo NO ... in a directory where the pictures are. ...