expect ssh script cannot finish and exit

All
i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $

#!/usr/bin/expect
set timeout 10

set arg [lindex $argv 0]
set arg1 [lindex $argv 1]


spawn ssh -l UserA 1.1.1.1
expect "assword:";
send "PasSwOrD\r";
expect "$";
send "telnet 2.2.2.2\r";
set timeout 260
expect "login:";
send "UserA\r";
expect "Password:";
send "PasSwOrD\r";
expect ">";
send "exit\r";
expect "$";
send "exit\r";

expect eof

exit;
[root@sam BUM]# ./testtelnet
spawn ssh -l UserA 1.1.1.1
UserA@203.98.129.43's password:
Last login: Sat Jul 23 08:23:57 2011 from x.x.x.x
Sun Microsystems Inc.   SunOS 5.8       Generic Patch   October 2001
Could not chdir to home directory /home/UserA: No such file or directory
Sun Microsystems Inc.   SunOS 5.8       Generic Patch   October 2001
$ telnet 2.2.2.2
UserA
Trying 2.2.2.2...
Connected to 2.2.2.2.c
Escape character is '^]'.

Host2 (ttyp0)

UserA
login: Password:

--- JUNOS 10.4 built 2011-05-27 07:22:52 UTC
{master}
UserA@Host2> exit

Connection closed by foreign host.
$

....
..
.

then hanging there and no response...
how i can end this correctly ?

thanks a lot everyone

I'm not sure, but possibly the "$" is taken in some special meaning. Try

expect -ex "\$"

In any case you may get more insight into the script's operation by adding

exp_internal 1

at the beginning