Leo, There are so many free apps/scripts out there that do this exact thing. I have been away from webhosting for a while, but I think that Matt's Scripts may have something. I would start there. You may not find exactly what you want, but you should find a good starting script to modify. Good Luck.
Be careful when using that site. Long ago I made the mistake of googling it and suggesting it and was castigated by a few elder monks for suggesting it.
To Quote:
ChrisCantrall: If you're going for a bad example, it might be ok. :)