开发者

Read HTTP output using shell/bash script

My url (http://myhost.com/getuser/Default.aspx?username=b772643) returns the following line of of info always:

John, Tho开发者_如何学JAVAmas;John.B.Thomas@Company.com

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.


Curl or wget are obviously better for the job but for the record bash and Unix standard commands (cat & printf) can do the job.

ksh introduced shell network internal handling and this has been adopted by 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


One liner:

(echo 'GET /getuser/Default.aspx?username=b772643' > /dev/tcp/myhost.com/80);


so

curl "http://myhost.com/getuser/Default.aspx?username=b772643"


curl "http://myhost.com/getuser/Default.aspx?username=b772643"| sed 's/\(.*\);\(.*\)/\2 \1/' | while read email name; do echo =$email=$name=; done


You could use :

curl "http://myhost.com/getuser/Default.aspx?username=b772643"

and extract the datas from what is returned :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜