I’ve been wanting to monitor the logfiles from some website I manage, but unfortunately for me, the provider uses a method of shared hosting that does not provide SSH access.
Because of that, I can’t SSH into the “box” and tail the logfile to get my real-time data.
Thankfully, WIll Moffat from http://hamstersoup.com has produced a simple but very efficient Perl script called ftptail. This script will connect via FTP and use clever commands to refresh the file size, and then “resume” the transfer to only get the latest bytes. All in all, it produces an almost realtime stream of data that can be written to a file and get itself “tail’d” to feed other processes.
The script is thoroughly explained on his blog entry.
Here’s how I use it.
First I copied the script to /usr/local/sbin/, and chmod it 755 so everyone can use it. Then I wrote the password of my ftp user into a file “passwd.txt” that is only readable by me. So I chmod that file 500. Finally I launch it this way:
/usr/local/sbin/ftptail -s 1 -f -p passwd.txt myusera@someserver.com/access-logs/my_acces_log > website_ftptail.log
This creates the local file “website_ftptail.log” that I can have other processes tail and do interesting stuff with it.
Of course this is rather crude, I would probably need to cycle the file daily so it doesn’T grow too big. Another post…