Friday, 9 August 2013

Output screen session to text file (overwrite) to make it accessible through website

Output screen session to text file (overwrite) to make it accessible
through website

I use screens so I am able to easily monitor several running processes.
A sample: screen -A -S trafficMonitor which has iptraf -d eth0 running. To
enter it I use screen -x trafficMonitor
But I want this screen (trafficMonitor) to be logging/sending output to
/var/www/currentTraffic.txt (overwrite each 5 seconds).
So I check out the servers traffic activity without logging in through SSH.
I was playing around in PHP trying to do this, but I am a novice to linux
commands, especially when it comes to PHP interacting with the terminal.
After reading around I eventually dropped that idea as it might come with
security problems as well. So just logging the output to web directory
without actually using PHP sounds like a safe way to deal with it.
Googling around the closest I got to an answer was screen -L (tried stuff
like screen -A -S trafficMonitor -L /var/www/trafficMonitor.txt but this
obvious wishful thinking didnt work.), and hours of trying various things
I am stuck and sad of my own incompetence.
I want to view mywebsite.com/trafficMonitor.txt and see the servers
network traffic usage. (basically the iptraf -d eth0 screen) with an
update interval of 5 seconds. (not streamed).
Any sample code or help in general highly appreciated!

No comments:

Post a Comment