#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Curl return error and print/email error code


    I am looking for a way to use curl (www dot somewebsite dot com) and check the error code, and if greater than 0, log it and/or email.

    Thinking an if statement would work, but not entirely sure.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Posts
    22
    Rep Power
    0
    I presume your talking about using the CuRL command than the library. If you were use the CuRL command in your program. Then for certain you would use system function to call it right? In that case you can only rely on the system return code than the CuRL return code. From the system doc

    The return value is the exit status of the program as returned by the wait call
    That would effectively be what the CuRL would return. The if statment would abosutly do the job.

    perl Code:
     
    my $Err = system( <<Curl command>> );
    if( $Err == -1 )  
    { print STDERR "CuRL failed" ; }
    else {
       if( $? & 127 )  
       { print STDERR "CuRL failed for other reason; check the documentation"; }
    }


    Or why not use the WWW.Curl library?

    ssharish2005
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Can you describe end goal leaving the actual implementation perl/curl/etc out of it? It sounds like you're trying to create a script to check if a webserver is alive, and then log the result. If so, there may be a simpler way to do it.

    LWP and LWP::Simple cover most use cases for HTTP via perl. HTTP::Tiny is a simpler interface (and is included in the core libraries).

    There's also Net::HTTP that provides a lower-level interface, and it's not too difficult to just open a socket and write out a one-line HTTP request. If just making sure something is listening on a port is enough, Net::Ping may make things simpler.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo