Print Out A Random Futurama Quote

25th June 2008 - 2 minutes read time

If you sent a curl request to the slashdot.org server you get back a random Futurama quote contained within the header information. The following curl command:

curl -Is slashdot.org

The commands supplied are I and s. I causes only the header of the file to be shown and s stops curl printing out anything. This returns the following headers:

HTTP/1.1 200 OK
Date: Wed, 25 Jun 2008 08:34:43 GMT
Server: Apache/1.3.41 (Unix) mod_perl/1.31-rc4
SLASH_LOG_DATA: shtml
X-Powered-By: Slash 2.005001
X-Bender: I'm an outdated piece of junk.
Cache-Control: private
Pragma: private
Connection: close
Content-Type: text/html; charset=iso-8859-1

Which contains a quote from Bender. To grab the correct line we then pass this through a regular expression to find a line that starts with an "X" and a dash, followed be either a B (for Bender) or an F (for Fry). The following line:

curl -Is slashdot.org | egrep '^X-(F|B)'

Will print off the line from the above header information.

X-Bender: I'm an outdated piece of junk.

We can then cut apart the string to extract everything after the "X-". This is done with the cut command.

curl -Is slashdot.org | egrep '^X-(F|B)' | cut -d \- -f 2

I this case the cut command splits the string by the dash and then returns the second part of it, which contains the quote we need. The final outputted line is as follows:

Bender: I'm an outdated piece of junk.

Try this for yourself!

Comments

Permalink
You can also get the quote via the PHP get_headers() function, like so: If you can see a better way of doing it, please let me know!

Jamie Bicknell (Thu, 01/22/2009 - 18:06)

Permalink
@Jamie - I think Wordpress killed off the code you put in, but I understand what you are on about. Using get_headers() to get an array of the headers, and then getting the X-Bender (or whatever) array item.

Add new comment

The content of this field is kept private and will not be shown publicly.