Thread Clean Script (8 answers)
Opened by Gast at 2006-05-22 20:19

renee
 2006-05-22 20:58
#7743 #7743
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
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
# Deletes players which haven't logged for a week and have level below 30
use strict;
use warnings;
use Tie::File;

my $days = 7;
my $minlevel = 30;
my $counter = 0;

for $file (glob "../data/players/*"){
next unless $file =~ /xml$/;
open(my $fh, "<", $file) or die $!;
@content = <FILE>;
$_ = "@content";
close(FILE);

my ($account) = $_ =~ /account="(\d+)"/;
my ($lastlogin) = $_ =~ /lastlogin="(\d+)"/;
my ($level) = $_ =~ /level="(\d+)"/;

my $playername = ''; # muss Du wissen, wie Du auf den Playernamen kommst!

if ((time() - $lastlogin) > $days*24*3600 && $lastlogin > 0 && $level < $minlevel){
for my $local_file($file,"../data/accounts/$account.xml","../data/vip/$account.xml"){
tie my @array,'Tie::File',$local_file) or die $!;
@array = grep{$_ !~ /$playername/}@array;
untie @array;
}
print "$file\n";
$counter++;
}
}
print "$counter acccounts deleted\n";
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Clean Script