using shell script to telnet

I would like to log into a server read a certain file and get the results back. I have tried like below to no avail;

#!/bin/ksh -x

(
sleep 2
echo sdpuser
sleep 2
echo cs3reloaded
sleep 5
cd /export/home/scripts/daily_checks
sleep 5
head daily_check_report.txt > test160108.txt
exit
) | telnet absdpb2

I have had some success with a ksh coprocess. Example:
changepass automate password changes on multiple systems

just for reading a file...

ftp -in ftp.server.com<< EOF 
user anonymous abcd@email.com
 get file  - 
EOF

Use Netcat (in OpenSolaris based distributions) with -t flag to script telnet sessions.

More info about Netcat (nc(1)) in Solaris is here

i was going to say netcat, but you could also do expect or perl.

do you want it to read real time, or just a one time process? i have a perl script that tails a file and writes the updates somewhere else if you'd like it.

Most implementations telnet doesn't read from stdin. Also the way you have the code written, the file will be created on the system you are telneting to, not the one you are telneting from.

Easiest way on a modern unix box is to use ssh. (Should be included) and do something like this:
_____________________
#!/bin/ksh -x

echo "
cd /export/home/scripts/daily_checks
head daily_check_report.txt
" | ssh absdpb2 > test160108.txt
______________________
If you add yourself to the authorized_keys on absdpb2 you won't even have to answer the userid and password question.

If ssh is not an option, then use the open source package expect. Google expect or "expect tcl" to learn more.

First of all - telnet is not secure in any way. Try to use something different if possible.

You might want to check 'expect' - this could be useful for your purpose.

Try to avoid keeping passwords in the script files. I would advise SCP/SFTP with keys authentication. If this is not possible then FTP.

Regards