www/60375: [FILE] Cleans sendpr-code db by removing expired codes.
Eric Anderson
anderson at centtech.com
Thu Dec 18 12:50:16 PST 2003
>Number: 60375
>Category: www
>Synopsis: [FILE] Cleans sendpr-code db by removing expired codes.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-www
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Dec 18 12:50:13 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Eric Anderson
>Release: 5.2-CURRENT
>Organization:
>Environment:
5.2-CURRENT FreeBSD 5.2-CURRENT
>Description:
Perl program that is cronable - removes stale codes from sendpr db based on an expired time.
Ceri requested this.
>How-To-Repeat:
No problems reported yet.. :)
File for Ceri..
>Fix:
#!/usr/bin/perl -T
#
#
#
# Copyright (c) 2003 Eric Anderson
use DB_File;
use Fcntl qw(:DEFAULT :flock);
use strict;
$ENV{"PATH"} = "/bin:/usr/bin";
$ENV{"TMPDIR"} = "/tmp";
my($fd, $db_obj, %db_hash, $currenttime, $randomcode, $expiretime, $dbpath);
############################################
$dbpath = "/tmp/sendpr-code.db";
$expiretime = 900; # seconds until code expires
############################################
$currenttime = time();
# DB stuff here
$db_obj = tie(%db_hash, 'DB_File', $dbpath, O_CREAT|O_RDWR, 0644)
or die "dbcreate $dbpath $!";
$fd = $db_obj->fd;
open(DB_FH, "+<&=$fd") or die "fdopen $!";
unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
}
foreach $randomcode (keys %db_hash) {
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
delete $db_hash{"$randomcode"};
}
}
$db_obj->sync(); # to flush
flock(DB_FH, LOCK_UN);
undef $db_obj;
untie %db_hash;
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-www
mailing list