Hi Dear Monks
I have a task to develop the script in perl to rotate the log based on the threshold size and the number if iterations which has been given in the config file.
Below is the content of the config file
########################################################### #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
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 file
Below 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.
$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"; } } }
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.

In reply to Log rotaion for the files which are existed in the absolute paths from the config files by perladdict

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.