Linux script telnet HEAD request [duplicate]

折月煮酒 提交于 2019-12-06 14:57:55

Your script just prints some stuff to stdout. It doesn't actually execute the telnet command. Try something like this:

telnet $1 $2 <<< $'HEAD $3 HTTP/1.0\r\n\r\n'

This will run telnet instead of just printing the command out. It also feeds in the HEAD command on stdin. It's important to send \r\n line endings rather than UNIX's default \n line endings, since \r\n is what the HTTP protocol requires.

See man bash for a description of the <<< operator.

You aren't actually running the telnet command anywhere. You just echo it to the screen.

Drop the echo from that line.

That being said that won't work either because you don't get an interactive telnet session in a script that way.

You might be able to pipe input to telnet to give it strings to send to the remove host but I'm not sure.

You can use something like netcat/nc instead of telnet for this (which is likely a good idea anyway) as they definitely can take input via a pipe.

You could also just use a tool built for this like curl (curl -I).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!