Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-24 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found