使用 shell/bash 脚本读取 HTTP 输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5951029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Read HTTP output using shell/bash script
提问by baluchen
My url (http://myhost.com/getuser/Default.aspx?username=b772643) returns the following line of of info always:
我的 url (http://myhost.com/getuser/Default.aspx?username= b772643) 总是返回以下信息行:
John, Thomas;[email protected]
I wish to read this line using a shell or bash script without wget/lynx. I'm in a situation where I cannot use any other utility, the perl language etc.
我希望使用没有 wget/lynx 的 shell 或 bash 脚本来阅读这一行。我处于无法使用任何其他实用程序、perl 语言等的情况。
回答by jlliagre
Curl or wget are obviously better for the job but for the record bash and Unix standard commands (cat & printf) can do the job.
curl 或 wget 显然更适合这项工作,但对于记录 bash 和 Unix 标准命令(cat & printf)可以完成这项工作。
ksh introduced shell network internal handling and this has been adopted by bash.
ksh 引入了 shell 网络内部处理,这已被 bash 采用。
#!/bin/bash
exec 5<> /dev/tcp/myhost.com/80
cat <&5 &
printf "GET /getuser/Default.aspx?username=b772643 HTTP/1.0\r\n\r\n" >&5
回答by ethree
One liner:
一个班轮:
(echo 'GET /getuser/Default.aspx?username=b772643' > /dev/tcp/myhost.com/80);
回答by jm666
so
所以
curl "http://myhost.com/getuser/Default.aspx?username=b772643"
curl "http://myhost.com/getuser/Default.aspx?username=b772643"| sed 's/\(.*\);\(.*\)/ /' | while read email name; do echo =$email=$name=; done
回答by Cédric Julien
You could use :
你可以使用:
curl "http://myhost.com/getuser/Default.aspx?username=b772643"
and extract the datas from what is returned :)
并从返回的内容中提取数据:)