perladdict has asked for the wisdom of the Perl Monks concerning the following question:
In the above config the first field is the userid,second field is absolute path,3rd field is threshold size and the last field is number of iteration need to be done before archival of log files. I need to develop the script from bottom up approach,means first i need to check is there any file for ex a.log exist for three iteration i.e a1.log,a2.log and a3.log, if exist i need to archive the all the a1,a2,a3.logs,if not need to check that in each path is there any files exist with more than the threshold size as mentioned in the above config file and need to rename the a.log to a1.log and if a1.log reaches the threshold size then need to rename it to a1.log to a2.log and and a2.log to a3.log as mentioned in the last field in the above config fileBelow is the sample code i am trying to parse the config file, but i am not getting the how to strt with this task.Please guide me how to start with this implemetaion.########################################################### #This file has the details required for archival. #This is to be used for Log Roration script to be #excuted on each instance. #The columns are separated by a space. # #meshid absolutepathoflog/file thresholdsize iterationcount ########################################################### test0613 /opt/xxx/domains/test0613/dev/domain/test0613-dev/ipe/logs/*. +log 5MB 3 test0513 /opt/xxx/domains/test0513/dev/domain/test0513-dev/* 3MB 2 test0413 /opt/xxx/domains/test0413/dev/domain/test0413-dev/bw/logs/* 2 +MB 2 test0813 /opt/xxx/domains/test0813/dev/platform/log/*.log 5KB 4
From the above code i can able to print the absolute path for all the files for all the paths which exist in config file, but in $flsize i am not able to get the size of all the files, it is displaying as :No such files or directory. Monks it will be a greate help if you can guide me accomplish this task.$file = "logconfig2.txt"; open(F,$file) or die "can't open the file $!\n"; while($line=<F>) { chomp $line; if($line !~ /^#/) { ($id,$path,$size,$iter) = split(" ",$line); @ids = $id; @paths = $path; @sizes = $size; @iters = $iter; @files = `ls $path`; #print "$path\n"; foreach(@files) { $abspath = $path . $_; print "$abspath\n"; $flsize = `ls -lrt "$abspath" | awk -F" " '{print $5}'`; print "$flsize\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Log rotaion for the files which are existed in the absolute paths from the config files
by kcott (Archbishop) on Mar 27, 2014 at 21:15 UTC | |
by perladdict (Chaplain) on Mar 27, 2014 at 21:26 UTC | |
|
Re: Log rotaion for the files which are existed in the absolute paths from the config files
by Anonymous Monk on Mar 27, 2014 at 21:11 UTC | |
by Anonymous Monk on Mar 27, 2014 at 21:21 UTC |