| Line | |
|---|
| 1 | #
|
|---|
| 2 | # get_html -- get a web page from a remote server
|
|---|
| 3 | #
|
|---|
| 4 | # Original Author: Jeff Korn <jlk@cs.princeton.edu>
|
|---|
| 5 | # Modified for bash by Chet Ramey <chet@po.cwru.edu>
|
|---|
| 6 | #
|
|---|
| 7 | # Example: get_html cnswww.cns.cwru.edu /~chet/ | more
|
|---|
| 8 |
|
|---|
| 9 | get_html()
|
|---|
| 10 | {
|
|---|
| 11 | local host port
|
|---|
| 12 |
|
|---|
| 13 | (($# < 2)) && {
|
|---|
| 14 | echo "usage: $FUNCNAME hostname path [port]" >&2
|
|---|
| 15 | return 1
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | host="$1"
|
|---|
| 19 | port="${3:-80}"
|
|---|
| 20 |
|
|---|
| 21 | exec 3<> /dev/tcp/$host/$port || {
|
|---|
| 22 | echo "$FUNCNAME: $host/$port: cannot connect" >&2
|
|---|
| 23 | exit 1
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | echo -e "GET $2 HTTP/1.0\n" >&3
|
|---|
| 27 |
|
|---|
| 28 | cat <&3
|
|---|
| 29 |
|
|---|
| 30 | exec 3<&-
|
|---|
| 31 |
|
|---|
| 32 | return 0
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | get_html "$@"
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.