Skip to content
This repository
tree: 5663a1b065
Fetching contributors…

Cannot retrieve contributors at this time

executable file 36 lines (25 sloc) 0.785 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/perl -w

# reset_order_number -- date-based order numbers for Interchange

# From an idea posted to the interchange-users
# 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("#COUNTER-1.0\n%Y%m%d0000\n", localtime() );

close ON or die "close $fn: $!\n";
Something went wrong with that request. Please try again.