EverCrest Message Forums
You are not logged in. Login or Register.
Author
Topic: Little bash script
Nina
posted 11-30-2003 01:06:19 AM
I want to write a bash or perl script for my daily cron that'd get a rather simple task done. The task consists of this: To copy my EQ logs from my EQ folder to my server, timestamp by date and gzip them. It would only happen if my C drive is mounted (aka -- any time my workstation is open) and the logfile isn't currently open (aka -- when I'm playing EQ).

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?

Nina
posted 11-30-2003 04:31:12 AM
All working except the open file test. Either way, feel free to gank it if you feel it might be useful, gzipped logs are much smaller than pure text ones after all. =p

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 ]

Mr. Parcelan
posted 11-30-2003 04:33:26 AM
H.U.H.
Nina
posted 11-30-2003 02:35:34 PM
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.
Suddar
posted 11-30-2003 02:37:09 PM
your script is winking at me funny.
Holden
French Cocksucker
posted 11-30-2003 02:38:08 PM

"America is dumb, it's like a dumb puppy that has big teeth that can bite and hurt you..."
Canadian Mountee
Rumble Pak+FMV Sequence=FUN!
posted 11-30-2003 02:38:35 PM
<FOO>
The World is Yours
Drysart
Pancake
posted 11-30-2003 03:48:31 PM
Use rsync. It'll probably do the job better.
Naimah
In a Fire
posted 11-30-2003 04:17:05 PM
It would be easier to read if you used next line braces instead of end of line. But that is just a style issue.
Random Insanity Generator
Condom Ninja El Supremo
posted 11-30-2003 05:01:21 PM
I can give you a php hackjob script I put together to check for files to update...

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.

* NullDevice kicks the server. "Floggings will continue until processing power improves!"
-----------------------------------
"That was black magic, and it was easy to use. Easy and fun. Like Legos." -- Harry Dresden
-----------------------------------
That's what playing Ragnarok Online taught me: There's no problem in the universe that can't be resolved by the proper application of daggers to faces.
Iulius Kaesar
Pancake
posted 11-30-2003 10:21:21 PM
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.

All times are US/Eastern
Hop To: