Double Tall Iced Mocha, Lite on the Chocolate

September 20, 2004

whore.cgi

Filed under: /StupidShellTricks — @ 5:18 am

In my spare time I help sysadmin the box this site is on.
This generally means getting vhosts setup for people and showing them how to setup their mail client etc… Recently Jason moved his site and mail over so I have been setting up the webserver for him and what not. He sends me an email asking to make sure that his cgi-bin has execute permissions. So I go ahead and make sure the permissions are set properly and then as a good sysdamin, I decide to whip out a little one line bash cgi to test his cgi-bin and make sure my work there is done.

So it basically started out as:

#!/bin/bash

echo Content-type: text/plain

echo “”

echo “<html&gt<head><title>whore</title></head><body>whore</body></html>”

A simple little cgi that produces a lame web page that says “whore”. Whore is a term of endearment for us, we call each other whores all the time, so it I figured it would be kind of funny.

Then I thought, a cgi that produces a static page is really no fun. I need something dynamic about the page, I know I will change the format of the word “whore” every time the cgi gets executed. By this time I have invested about 15 minutes of time into this and I can see it progressively getting worse.

I decide that I will construct about 5 different formats of the word whore, and randomly select one each time the page is loaded. So then I think to myself, “Oh crap, how do you generate a random number in bash?”. Well that led to my next time suck:

Articles about random number generation in Bash

  • 1
  • 2
  • 3

    So know I am into this about 40 minutes, I have read some different ways to do what I want to do. I need to get this done so I can move on with my life.

    Here is the result: whore.cgi

    And the resulting code, becuase you really need to be able to do this.

    So to answer your question Jason, yes it looks your cgi-bin working… like a whore!

  • Leave a Reply

    Powered by WP-Hashcash.