Here's a start. There may be better ways of doing it, which I would be interested in if there are. You can execute something and take it's output as data and do stuff with that.
Here is an example which someone else did.
You can also look into making modules for apache or php. I don't know enough though to tell you how to do that. The links I have given to php and apache are just to their home sites.