I have a fair idea of how to do this, except for the file tests. What file test operator would be suitable to check if the log is already open, if there is one? Also, considering I'm real lazy with my smb mounts and I never unmount the C drive before shutting the workstation down, is there a way to make the -e check not take ages before failing?
code:#!/usr/bin/perl
# Small script to grab EQ logs and gzip them
use Fcntl qw/:flock/;
my $eqpath = '/home/shaitan/Games/EverQuest/';
my $logpath = '/root/eqlogs/';
if (-e $eqpath) {
(undef,undef,undef,$day,$month,$year,undef) = localtime(time);
$timestamp = sprintf("%0.4u",$year+1900) . sprintf("%0.2u",$month) . sprintf("%0.2u",$day);
opendir(EQDIR,$eqpath);
@logfiles = grep {/^eqlog.*/} readdir EQDIR;
closedir(EQDIR);
foreach (@logfiles) {
$thislog = $_;
if (/^eqlog_(.*)_(.*)\.txt/) {
$character = $1;
$server = $2;
}
open FOO, "+< $eqpath"."$thislog" or die "Can't open logfile: $!";
flock(FOO, LOCK_EX) or die "Couldn't lock logfile: $!";
seek(FOO,0,2) or die "EOF unreachable: $!";
seek(FOO,0,0);
unless (-z FOO) {
mkdir "$logpath".$server unless -e "$logpath".$server;
my $fpath = "$logpath".$server."/".$character."_".$timestamp;
open BAR, "> $fpath" or die "Couldn't open outfile: $!";
while (<FOO> { print BAR; };
system("gzip -f $fpath");
close BAR;
}
truncate(FOO,0);
close FOO;
}
}
[ 11-30-2003: Message edited by: Nina ]
Basically the script I had grabbed the tarball, made a backup of a conf file, extracted the tarball after verifying that it could indeed write to the directory then moved the conf file back... If you have php installed you could hack it up a bit and see if that would help...
Otherwise, I'd agree with Drys, rsync the files over.... or just do what I do and rar the whole dir over to the server.
quote:
Nina had this to say about Tron:
Eh. Replace the with a ). UBB glitch. Still haven't found a way to check for open logfiles, I'm not even sure EQ places a file lock of sorts on its logs in progress.
I seem to remember opening logs for a character that was logged in. Shouldn't be a problem.