accounting.cgi is a small CGI that we use in our living commune to manage expenses. When someone buys something for the group (usually, food), it’s entered in this little utility. On the first of every month, a cronjob gets the tool to send out emails to all of us, telling us who bought what, and who has to give how much money to who.
Setting up the accounting script is easy. First, edit the config options at the beginning of the file. Then put it somewhere where your webserver will be able to find it—like your cgi-bin directory. Finally, you have to set up a cron job to deliver email notifications each month.
The file starts with the following prelude:
# Config options.
my $basedir = "/var/db/accounting";
my @people = ("joe", "jeff", "gina");
my %peopleip = ("joe" => "192.168.1.17",
"jeff" => "192.168.1.23",
"gina" => "192.168.1.42"
);
Adjust it to your needs. The webserver needs to be able to create files in $basedir. The @people array is a list of people in your group, while %peopleip assigns an IP to each of you—this is used to set a default username.
To get the script to send out mails once a month, create a new file named /etc/cron.monthly/accounting with the following content:
#!/bin/sh
# Send a mail about the accounting
/var/www/cgi-bin/accounting.cgi \
| mail -s "$(date -d "last month" \
+"Accounting %B %Y")" \
all@foo.org
Here, all@foo.org is the address to send the reports to. Of course, you have to adjust the path to the script as well.
That’s all—if you want to download it, you can do so now. I hope it works just as well for you as it works for us.