How to create a shell script to automate telnet?

While I am login in my shool Unix system. I'd like
to do use telnet to get homepage, for example "telnet 80" "GET /index.html HTTP/1.0\n\n" This works.
But if I put "GET /index.html HTTP/1.0\n\n" into a
file . and do "telnet 80<afile", this won't work.
Who is Participating?
dhughes111797Connect With a Mentor Commented:
telnet is an interactive program. It expects input from a terminal attached device (tty). As ozo said, you can use
a program like expect that acts like a modem chat script to
'expect' something and then 'send' something else. You cannot
make telnet take input from a file (or ftp for that matter -
thought ftp does have a .netrc that you can do some things
expect -
(requires Tcl -

If you have expect
expect -c 'spawn telnet 80; expect "Connected"; send "GET /index.html HTTP/1.0\r\r"; expect "Connection closed"'
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.