This comes up all the time on the expect.pm list.
Since you have AIX, put SSH on the database box, then use the expect.pm perl module to spawn an slogin to it from the linux box. Expect.pm can then handle all of the output and response stuff pretty easily. The reason I say use ssh instead of telnet is that automating telnet requires that you save an unecrypted password somewhere. This is a bad idea.