[lug] Fwd: Simple counter?

Anthony Foiani tkil at scrye.com
Fri May 24 19:09:28 MDT 2013

Derp, I missed these points.

My solution uses a plain text file; a bit slower to parse/write than
binary, but easier to use from the command line.  In particualr:

"Jeffrey S. Haemer" <jeffrey.haemer at gmail.com> writes:

> It would be nice if I could give it a seed -- "start with 12" or
> something -- but that's not critical.

Write the value to the file before you start using it.  Or anytime
after using it.  

(But note that I'm only using advisory locks, so if you muck with it
while an instance of 'counter' is trying to use the file, you might
corrupt things.)

> It would be nice if I could ask it what the next number will be
> without bumping the counter.  Also not critical.

It's a text file; just 'cat' it.

> It would even be nice if it offered remote access, so all machines
> could use the same counter.  Again, not critical.

ssh 'cat ...'

Although I could see 'counterd', which is a server... ;->

> Honest: this isn't "How can I write a simple program to do this?"
> It's, "Hasn't someone created a simple, standard utility that does
> this in the past 20 or 30 years?"

It's simple enough that I could write mine in less than an hour (and
it would have been 5min if I weren't being picky about return values).

It's complex enough (look at your requests above -- starting value,
current value, next value, remote access) that there's probably not a
single easy way to satisfy everyone.  E.g., if you were to make it
network transparent, then you'd get complaints from the people who
only want to use it locally.


More information about the LUG mailing list