10

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.

1
  • 1
    just verified. i can use curl Commented May 10, 2011 at 14:00

4 Answers 4

24

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
Sign up to request clarification or add additional context in comments.

6 Comments

Is it possible to do this in one line?
@ethree Sure, just put all commands , semi-colon separated, in a single line. You might also create a shell function.
@ethree Please define "isn't very happy" in more technical and descriptive terms.
Well, I think it's getting upset about the &'s. -bash: syntax error near unexpected token `;'
@ethree You probably put too much semicolons, please post the line you have issues with, that one works fine with me: (exec 5<> /dev/tcp/www.google.com/80;cat <&5 &;printf "GET /index.html HTTP/1.0\r\n\r\n" >&5)
|
5

One liner:

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

Comments

4

You could use :

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

and extract the datas from what is returned :)

Comments

3

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

1 Comment

Thanks to everyone. all solution works good. Curl is best one curl "myhost.com/getuser/Default.aspx?username=b772643"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.