HTTP Request from a shell script - Pinging Google
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > HTTP Request from a shell script - Pinging Google




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    HTTP Request from a shell script - Pinging Google  
mrbowes@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

I am trying to automate the process of pinging Google to let them know
that we have updated our Google sitemap. They require an HTTP request
be sent to them.

How can I do this in a shell script?

Thanks so much.

Regards,


Josh






[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Mark Warburton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

Hi Josh.  What you need is "wget" or "curl". Just use whichever is
available on your system -- both can send HTTP requests from the
command line (or a shell script).

Cheers,
Mark.






[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
mrbowes@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

Mark,

Thanks for the reply.

man wget and man curl return  "No manual entry for xxx" so I don't
think I have those modules installed.

Is there any other way? Or should I look at installing these modules?
There's always a fair amount of process getting anything installed
around here, so if there's another way, it would be ideal.

-Josh






[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

mrbowes@gmail.com wrote:
> man wget and man curl return  "No manual entry for xxx" so I don't
> think I have those modules installed.

Well, either install wget, or try with netcat ...
you need to construct the HTTP request yourself then,
nevertheless, it can be done with netcat.

Rainer





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

mrbowes@gmail.com writes:

> Mark,
>
> Thanks for the reply.
>
> man wget and man curl return  "No manual entry for xxx" so I don't
> think I have those modules installed.
>
> Is there any other way? Or should I look at installing these modules?
> There's always a fair amount of process getting anything installed
> around here, so if there's another way, it would be ideal.

You don't need them you can directly write network stuff with bash:

------------------------------------------------------------------------
#!/bin/bash

url="$1"
case "$url" in
http://*)
true
;;
*)
echo Usage:
echo "   $(basename $0) http://...  > resource"
exit 1
;;
esac

str="${url:7}"
str="${str/\/*}"
case "$str" in
*@*)
lpart="${str/@*}"
rpart="${str#*@}"
;;
*)
lpart=""
rpart="$str"
;;
esac

case "$lpart" in
*:*)
user=${lpart/:*}
pass=${lpart#*:}
;;
*)
user="$lpart"
pass=""
;;
esac

case "$rpart" in
*:*)
host=${rpart/:*}
port=${rpart#*:}
;;
*)
host="$rpart"
port=80
esac

(
printf "GET %s HTTP/1.0\r\n\r\n" "$url" 1>&3
cat 0<&3
) 3<>/dev/tcp/$host/$port

exit 0
------------------------------------------------------------------------

--
__Pascal Bourguignon__                     http://www.informatimago.com/

THIS IS A 100% MATTER PRODUCT: In the unlikely event that this
merchandise should contact antimatter in any form, a catastrophic
explosion will result.





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

Pascal Bourguignon wrote:
> mrbowes@gmail.com writes:
> 
>
> You don't need them you can directly write network stuff with bash:
>
> ------------------------------------------------------------------------
> #!/bin/bash

> (
>     printf "GET %s HTTP/1.0\r\n\r\n" "$url" 1>&3
>     cat 0<&3
> ) 3<>/dev/tcp/$host/$port

I checked two Unix systems (OS X and Solaris), and neither of them
seemed to have a /dev/tcp that could be used in this manner.  So
I guess that works only on certain systems.

- Logan





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

mrbowes@gmail.com wrote:
> man wget and man curl return  "No manual entry for xxx" so I don't
> think I have those modules installed.
>
> Is there any other way? Or should I look at installing these modules?

It sounds like you're in an environment where administrative restraints
may be more of a difficulty than technical ones.  Which is unfortunate,
because it often makes things into more work than necessary.  (And wget
and curl are hardly exotic software, incidentally.)

One other possibility is to do what you want to do with perl.  PERL is
often installed on systems as a standard thing, so it might be there.
With any luck, it is, and libwww-perl is also installed.  If so, it
should be just a matter of using the HTTP::Request class.  There is
some documentation at http://search.cpan.org/~gaas/libwww-perl-5.805/ .

You can test if you have HTTP::Request by doing this:

perl -M'HTTP::Request' -e 1

Another possibility, if you don't have it and can't get it installed,
but you still have perl, is to do it directly in perl.  "perldoc perlipc"
should have some documentation about how to use Perl's socket interface.

Doubtless similar scripts could be whipped up fairly easily in other
languages, like Python or Ruby, for example.

- Logan





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

Logan Shaw <lshaw-usenet@austin.rr.com> writes:

> Pascal Bourguignon wrote: 
> 
>
> I checked two Unix systems (OS X and Solaris), and neither of them
> seemed to have a /dev/tcp that could be used in this manner.  So
> I guess that works only on certain systems.

It works on systems that have bash (perhaps some modern version of bash).

/dev/tcp/$h/$p is a virtual device simulated by bash itself.


--
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Theo v. Werkhoven


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

The carbonbased lifeform Pascal Bourguignon inspired comp.unix.programmer with:
> Logan Shaw <lshaw-usenet@austin.rr.com> writes:
> 
>
> It works on systems that have bash (perhaps some modern version of bash).
>
> /dev/tcp/$h/$p is a virtual device simulated by bash itself.

I have no idea how you got that notion, but Bash knows nothing about
devices (not even when run with UID 0 permissions), only about files.
Use 'netcat' for those applications.

Theo
--
theo at van-werkhoven.nl    ICQ:277217131                      SuSE Linux
linuxcounter.org: 99872  Jabber:muadib at jabber.xs4all.nl  AMD XP3000+ 1024
MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
de uitwassen *van* Microsoft"





[ Post a follow-up to this message ]



    Re: HTTP Request from a shell script - Pinging Google  
Stefaan A Eeckels


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 02:01 PM

On Sat, 11 Nov 2006 07:17:01 +0100
Pascal Bourguignon <pjb@informatimago.com> wrote:

> /dev/tcp/$h/$p is a virtual device simulated by bash itself.

Yikes, what an abomination.

First we had Emacs with OS pretensions, now we have bash.

--
Stefaan A Eeckels
--
Sometimes I wonder whether the world is run by smart people who are
putting us on or by imbeciles who really mean it.      --Mark Twain





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:24 AM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register