无法自动telnet

无法自动telnet

现有一脚本用于自动telnet,脚本如下:
(    sleep 2
     echo "UserName";
     sleep 1
     echo "PASSWORD";
     sleep 1
     echo "command1";
     sleep 1
     echo "command2";
     sleep 1
     echo "command3";
     sleep 1
     echo "command4";
     sleep 1
     echo "exit";
     ) | telnet Server_ip   

运行时,当运行到输入password时,就自动断开了,显示如下:
Trying...
Connected to 10.127.0.1
Escape character is '^]'.
Local flow control on
Telnet TERMINAL-SPEED option ON

HP-UX  ....

login: ll

Password: Connection closed by foreign host.

但手动telnet到该机器是正常的,
不知如何解决?非常感谢      
俺这里试着是可以的:
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=19305 $?=0] ; cat foo.sh
#!/bin/bash

echo foo
sleep 1
echo foo
sleep 1
echo exit
sleep 1
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=19305 $?=0] ; ./foo.sh | telnet localhost
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Ubuntu 6.06.2 LTS
ubuntu606 login: foo
Password:
Last login: Wed Jul 23 18:55:02 2008 from localhost on pts/22
Linux ubuntu606 2.6.15-51-386 #1 PREEMPT Tue Feb 12 16:52:52 UTC 2008 i686 GNU/Linux

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
foo@ubuntu606:~$ exit
logout
Connection closed by foreign host.
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=19305 $?=1] ; bye
      
用 expect 试试呢?