#75 Creating a Text-Based Web Page Counter

One popular element of many web pages is a page counter that increments each time a request for the page in question is served. A quick glance at the counter value then lets you see how popular your pages are and whether they're seeing lots of visitors. While counters aren't typically written as shell scripts, that doesn't mean it can't be done, and we'll throw caution to the wind and build it ourselves!

The fundamental challenge with this particular script is that there's a possible race condition, a situation in which two people visit the page simultaneously and each of the counter scripts steps on the other when writing to the data file. You can try to solve the race condition within the script ...

Get Wicked Cool Shell Scripts now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.