سلام عليكم...
أخوكم مزنووووق
عندي كود بيرل
وماني عارف اعدل فيه
وانا ما ادري ايش يعني بيرل حتى
المشكلة فين ؟؟؟
المشكلة ان الكود محدد
المسار اللي يأخذ منه الملفات ويقرأها..
ماذا تريد؟؟؟
اللي أبغاه ان البرنامج يطلب من المستخدم
مكان الفولدر
وخلاص سلامتكم....
وهذا الكود
open (SRVLIST, "servlist.txt") or die "Can't find servlist.txt in current directory";
@server_name = ();
@server_name = <SRVLIST>;
for my $server (@server_name) {
chomp($server);
}
close SRVLIST;
open (OUTLOG, ">>floggerLOG.txt");
foreach $server (@server_name) {
$log_dir = "\\\\$server\\Tracking.Log\\";
$current_time = localtime(time);
print "\n$current_time\n";
print "server is $server\n";
print OUTLOG "\n$current_time\n";
print OUTLOG "server is $server\n";
($today) = (localtime)[3];
opendir (CURR, $log_dir) or die "can't open directory: $!\n";
while (defined($file = readdir(CURR))) {
if ($file =~ m/log/){
use File::stat;
$file_stats = stat($log_dir . $file);
$mod_time = $file_stats->mtime;
use Time::localtime;
$tm = localtime($mod_time);
$mod_day = $tm->mday;
if ($mod_day != $today) {
use File::Copy;
copy ($log_dir . $file, $file);
print " $file was not modified today, copied to this directory\n";
print OUTLOG " $file was not modified today, copied to this directory\n";
}
}
}
closedir (CURR);
#--------------------List the log files-----------------------------
#This part builds a list of all files in the current directory that
# end in .log
# We'll use this list to build the statistics for each user for the
# particular day that the log file corresponds to
use Cwd;
$this_dir = cwd();
opendir (THISDIR, $this_dir) or die "can't open directory: $!\n";
while (defined($log_file = readdir(THISDIR))) {
if ($log_file =~ m/\.log/) {
&parse_log($log_file);
unlink $log_file;
}
}
closedir (THISDIR);
}
#^-----------------------------------------------------------------^
close OUTLOG;
#####################################################################
#####################################################################
sub parse_log {
$current_log = $_[0];
$data_out = $server . substr($current_log, 4, 4) . "\.csv";
# For this script, a message block is composed of the group
# of log file lines separated by blank lines before and after
%message_id_hash = ();
#--------Load the tracking log into a hash of arrays-------------
open (FILE, $current_log) or die "Can't find the file specified";
$/ = "";
while (<FILE>) { #read each message block, not each line
#print "**********\n $_ \n*****************";
$temp_string0 = "";
@temp_list0 = ();
# $_ will contain the message block
#replace all newlines with tabs in the message block
s/\n/\t/g;
$temp_string0 = $_;
@temp_list0 = split(/\t/, $temp_string0);
$message_id = uc$temp_list0[0];
push @{ $message_id_hash{$message_id}}, [ @temp_list0 ];
}
close FILE;
#^-------------------------------------------------------------^
# At this point, we have a hash where the key is the Message ID
# and the value is an array of arrays, where the arrays are the
# message blocks
$num_keys = keys %message_id_hash;
print "There are $num_keys messages in the log file $current_log\n";
print OUTLOG "There are $num_keys messages in the log file $current_log\n";
#---------------------Build the hash of arrays that--------------
#---------------------contains the sent/received information-----
#---$user_msg_counts_hash{$sender_id}[0] = total number of messages sent
#---$user_msg_counts_hash{$sender_id}[1] = number sent to local server
#---$user_msg_counts_hash{$sender_id}[2] = number sent to an Org server
#---$user_msg_counts_hash{$sender_id}[3] = number sent to internet
#---$user_msg_counts_hash{$sender_id}[4] = total size (KB) sent
#---$user_msg_counts_hash{$sender_id}[5] = size (KB) sent to local server
#---$user_msg_counts_hash{$sender_id}[6] = size (KB) sent to an Org server
#---$user_msg_counts_hash{$sender_id}[7] = size (KB) sent to internet
#---$user_msg_counts_hash{$sender_id}[8] = total number of recipients on messages
#---$user_msg_counts_hash{$sender_id}[9] = number of local recipients on messages
#---$user_msg_counts_hash{$sender_id}[10] = number of Org recipients on messages
#---$user_msg_counts_hash{$sender_id}[11] = number of internet recipients on messages
#---$user_msg_counts_hash{$sender_id}[12] = total number of messages received
#---$user_msg_counts_hash{$sender_id}[13] = number received from local server
#---$user_msg_counts_hash{$sender_id}[14] = number received from an Org server
#---$user_msg_counts_hash{$sender_id}[15] = number received from internet
#---$user_msg_counts_hash{$sender_id}[16] = total size (KB) received
#---$user_msg_counts_hash{$sender_id}[17] = size (KB) received from local server
#---$user_msg_counts_hash{$sender_id}[18] = size (KB) received from an Org server
#---$user_msg_counts_hash{$sender_id}[19] = size (KB) received from internet
$msg_id = "";
%user_msg_counts_hash = ();
#Loop through each key ($msg_id)
for $msg_id (keys %message_id_hash){
#---------------Check for sent message--------------------------------------
#Check to see if the message is a sent message (event 1000 or 7)
# and increment appropriate counters
for $j (0 .. $#{ $message_id_hash{$msg_id}}) {
if ($message_id_hash{$msg_id}[$j][1] == 1000 || $message_id_hash{$msg_id}[$j][1] == 7){
if ($message_id_hash{$msg_id}[0][6] =~ m/Recipients\/cn=\w+/i) {
$sender_id = uc(substr($&,14));
} else {
$sender_id = "unknown1000or7";
}
$user_msg_counts_hash{$sender_id}[0]++;
$user_msg_counts_hash{$sender_id}[4] += sprintf("%.1f", $message_id_hash{$msg_id}[$j][8]/1024);
last;
}
}
#^-------------------------------------------------------------------------^
#----------------Messages from the local server to the local server-------------
#Loop through each message block associated with the current key ($msg_id)
for $k (0 .. $#{ $message_id_hash{$msg_id}}) {
#check for local message and increment appropriate counters
if ($message_id_hash{$msg_id}[$k][1] == 1000) {
#Identify sender and increment sender's sent counts
if ($message_id_hash{$msg_id}[$k][6] =~ m/Recipients\/cn=\w+/i) {
$sender_id = uc(substr($&,14));
} else {
$sender_id = "unknown1000";
}
$user_msg_counts_hash{$sender_id}[1]++;
$user_msg_counts_hash{$sender_id}[5] += sprintf("%.1f", $message_id_hash{$msg_id}[$k][8]/1024);
$user_msg_counts_hash{$sender_id}[8] += $message_id_hash{$msg_id}[$k][12];
$user_msg_counts_hash{$sender_id}[9] += $message_id_hash{$msg_id}[$k][12];
#pad out the array so that all elements will be defined
$user_msg_counts_hash{$sender_id}[19] += 0;
#Identify recipient(s) and increment recipient's counts
$array_length = $#{$message_id_hash{$msg_id}[$k]};
foreach $i (13 .. $array_length) {
if ($message_id_hash{$msg_id}[$k][$i] =~ m/Recipients\/cn=\w+/i){
$recipient_id = uc(substr($&,14));
} else {
$recipient_id = "unknown1000";
}
$user_msg_counts_hash{$recipient_id}[12]++;
$user_msg_counts_hash{$recipient_id}[13]++;
$user_msg_counts_hash{$recipient_id}[16] += sprintf("%.1f", $message_id_hash{$msg_id}[$k][8]/1024);
$user_msg_counts_hash{$recipient_id}[17] += sprintf("%.1f", $message_id_hash{$msg_id}[$k][8]/1024);
}
}
}
#^-----------------------------------------------------------------------^
#----------------Messages from the local server to an external server-------------
$org_not_counted = 1;
$internet_not_counted = 1;
#Loop through each message block associated with the current key ($msg_id)
for $m (0 .. $#{ $message_id_hash{$msg_id}}) {
if ($message_id_hash{$msg_id}[$m][1] == 7){
#Identify sender and increment sender's sent counts
if ($message_id_hash{$msg_id}[$m][6] =~ m/Recipients\/cn=\w+/i) {
$sender_id = uc(substr($&,14));
} else {
$sender_id = "unknown7";
}
$array_length0 = $#{$message_id_hash{$msg_id}[$m]};
foreach $h (13 .. $array_length0) {
if ($message_id_hash{$msg_id}[$m][$h] =~ m/SMTP/i) { #Internet recipient on message
if ($internet_not_counted) {
$user_msg_counts_hash{$sender_id}[3]++;
$internet_not_counted = 0;
}
$user_msg_counts_hash{$sender_id}[7] += sprintf("%.1f", $message_id_hash{$msg_id}[$m][8]/1024);
$user_msg_counts_hash{$sender_id}[8]++;
$user_msg_counts_hash{$sender_id}[11]++;
#pad out the array so that all elements will be defined
$user_msg_counts_hash{$sender_id}[19] += 0;
} else { #Org recipient on message
if ($org_not_counted) {
$user_msg_counts_hash{$sender_id}[2]++;
$org_not_counted = 0;
}
$user_msg_counts_hash{$sender_id}[6] += sprintf("%.1f", $message_id_hash{$msg_id}[$m][8]/1024);
$user_msg_counts_hash{$sender_id}[8]++;
$user_msg_counts_hash{$sender_id}[10]++;
#pad out the array so that all elements will be defined
$user_msg_counts_hash{$sender_id}[19] += 0;
}
}
}
}
#^----------------------------------------------------------------------^
#-----------------Messages from an external server to the local server-----------
#Loop through each message block associated with the current key ($msg_id)
for $n (0 .. $#{ $message_id_hash{$msg_id}}) {
if ($message_id_hash{$msg_id}[$n][1] == 9) {
$array_length1 = $#{$message_id_hash{$msg_id}[$n]};
foreach $i (13 .. $array_length1) {
if ($message_id_hash{$msg_id}[$n][$i] =~ m/Recipients\/cn=\w+/i){
$recipient_id = uc(substr($&,14));
} else {
$recipient_id = "unknown9";
}
if ($message_id_hash{$msg_id}[$n][6] =~ m/SMTP/i) {
$user_msg_counts_hash{$recipient_id}[12]++;
$user_msg_counts_hash{$recipient_id}[15]++;
$user_msg_counts_hash{$recipient_id}[16] += sprintf("%.1f", $message_id_hash{$msg_id}[$n][8]/1024);
$user_msg_counts_hash{$recipient_id}[19] += sprintf("%.1f", $message_id_hash{$msg_id}[$n][8]/1024);
} else {
$user_msg_counts_hash{$recipient_id}[12]++;
$user_msg_counts_hash{$recipient_id}[14]++;
$user_msg_counts_hash{$recipient_id}[16] += sprintf("%.1f", $message_id_hash{$msg_id}[$n][8]/1024);
$user_msg_counts_hash{$recipient_id}[18] += sprintf("%.1f", $message_id_hash{$msg_id}[$n][8]/1024);
}
}
}
}
#^-------------------------------------------------------------------------^
}
#^----------------------------------------------------------------------^
#---------------------Set any undefined array elements to 0--------------
$user1 = "";
for $user1 (keys %user_msg_counts_hash){
for $element (0 .. $#{ $user_msg_counts_hash{$user1}} ){
if (!defined $user_msg_counts_hash{$user1}[$element]) {
$user_msg_counts_hash{$user1}[$element] = 0;
}
}
}
#^----------------------------------------------------------------------^
#---------------------Print the resulting message count hash-------------
open (OUTPUT, '>' . $data_out);
print " now printing results to file $data_out\n";
print OUTLOG " now printing results to file $data_out\n";
print OUTPUT "*There are $num_keys messages in the log file\n";
print OUTPUT "*User,Total,Sent,Sent,Sent,Total,KBSent,KBSent,KBSent,";
print OUTPUT "TotalNum,NumLoc,NumOrg,NumInt,Total,";
print OUTPUT "Received,Received,Received,Total,KBRec,KBRec,KBRec\n";
print OUTPUT "*ID,Sent,Local,Org,Internet,KBSent,Local,Org,Internet,Recips,Recips,Recips,Recips,Received,";
print OUTPUT "Local,Org,Internet,KBRec,Local,Org,Internet\n";
$user = "";
$" = ",";
for $user ( keys %user_msg_counts_hash) {
print OUTPUT "$user,@{ $user_msg_counts_hash{$user} }\n";
}
close OUTPUT;
return 1;
} #End Sub parse_logواعتقد ان المكان اللي يبغاله تعديل هو:
$log_dir = "\\\\$server\\Tracking.Log\\";
انا ما افهم بيرل
ولكني فاهم كل مكان في ايش يسوي
فالذي يريد ايضاح اكثر يخبرني
