files2db.pl
上传用户:tany51
上传日期:2013-06-12
资源大小:1397k
文件大小:2k
- #!/usr/bin/perl
- require "db_api.pl";
- if (scalar(@ARGV) != 5) {
- &usage;
- exit;
- }
- &header;
- # remove a trailing /
- $dirpath = $ARGV[0];
- $dirpath =~ s!(.*)/$!$1!;
- $dbh = &db_init($ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4]);
- opendir FILEDIR, $dirpath or die "Error opening filedir!n";
- while ($filename = readdir FILEDIR) {
- if ($filename =~ m/^./) { next; } #ignore . and ..
-
- if ( ! (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
- $atime,$mtime,$ctime,$blksize,$blocks) = stat "$dirpath/$filename" )) {
- print "Error stat-ing the file $pathdir/$filename!n" ; next; }
-
- $type = ($mode & 070000) >> 12;
-
- if ($type != 0) {
- print "File $dirpath/$filename its not regularn";
- next;
- }
- convertfile2db("$dirpath/$filename");
- }
- closedir FILEDIR;
- sub convertfile2db {
- my $filen = shift;
- my ($userid, $count, $alist);
-
- open FILE, $filen or die "Error opening file $filenn";
- print "Converting file $filen ... ";
-
- $count = 0;
- $userid = ""; undef @alist;
- while($line = <FILE>) {
- if ($line =~ m/".*"=".*"/) {
- $line =~ m/^"([A-Za-z0-9]+)\\(.*)"="(.*)"/;
- $alist[$count]{tab} = $1;
- $alist[$count]{col} = $2;
- $alist[$count]{val} = $3;
- $alist[$count]{col} =~ s!\\!_!g;
- if ($alist[$count]{col} =~ m!userid$!) {
- $userid = $alist[$count]{val};
- }
- $count++;
- }
- }
- if ($userid ne "") {
- &db_set($dbh, $userid, $alist);
- }
- close FILE;
- print "donen";
- }
- sub header {
- print "Account files to db accounts converting tool.n";
- print " Copyright (C) 2002 Mihai RUSU (dizzy@roedu.net)n";
- print " People Versus People Gaming Network (www.pvpgn.org)nn";
- }
- sub usage {
- &header;
- print "Usage:nntfiles2db.pl <filedir> <dbhost> <dbname> <dbuser> <dbpass>nn";
- print "t <filedir>t: directory with the account filesn";
- print "t <dbhost>t: the database hostn";
- print "t <dbname>t: the database namen";
- print "t <dbuser>t: the database usern";
- print "t <dbpass>t: the database passwordn";
- }