Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, 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.

like image 295
baluchen Avatar asked May 10 '11 13:05

baluchen


3 Answers

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
like image 186
jlliagre Avatar answered Oct 15 '22 12:10

jlliagre


One liner:

(echo 'GET /getuser/Default.aspx?username=b772643' > /dev/tcp/myhost.com/80);
like image 4
ethree Avatar answered Oct 15 '22 12:10

ethree


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
like image 3
jm666 Avatar answered Oct 15 '22 12:10

jm666