[ic] Order prefix

Mike Heins interchange-users@lists.akopia.com
Thu Aug 2 19:13:01 2001


Quoting Mark Johnson (markj@redhat.com):
> Leon Harris wrote:
> > 
> > change etc/order.number in /var/lib/interchange/yourcatalog to something
> > other than TEST0000
> > 
> > I use an ugly little cron job to be run at one past midnight to generate the
> > date and 0000
> > 
> > eg
> > 1 0 * * *  (perl -e '($d,$m,$y)=(localtime)[3,4,5];printf "%04d%02d%02d%04d",
> > $y+1900,$m+1,$d,"0000";') > /var/lib/interchange/catalog/etc/order.number
> > 
> 
> LOL! That is too funny. New meaning to There's More than One Way to Do

This is a great idea!

If you have a busy store you might want to lock the file first. It
would very rarely cause trouble even in a busy store, but I have added
a little script to eg/.

#!/usr/bin/perl -w

# reset_order_number -- date-based order numbers for Interchange

# From an idea posted to the interchange-users@ic.redhat.com
# mail list by Leon Harris <leon@quoll.com>

# Place in crontab with 
# 
# 0 0 * * * /path/to/reset_order_number /path/to/catalog_dir

use Fcntl qw/:flock/;
use POSIX qw/strftime/;

my $dir = shift 
	or die "usage: $0 <catalog-directory-or-counter-file>\n";

my $fn;

if (-f $dir) {
	$fn = $dir;
}
else {
	$fn = "$dir/etc/order.number";
}

open ON, "+<$fn"
	or die "open $fn: $!\n";

flock    ON, LOCK_EX	or die "lock $fn: $!\n";
seek     ON, 0, 0       or die "seek $fn: $!\n";
truncate ON, 0          or die "truncate $fn: $!\n";

print    ON  strftime("%Y%m%d0000\n", localtime() );

close    ON             or die "close $fn: $!\n";

__END__

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

Being against torture ought to be sort of a bipartisan thing.
-- Karl Lehenbauer