Hello,
I'm trying to figure out a way to use a Perl script to modify a log file that is being written to by a production web server. Specifically, I need a way to extract lines with the previous day's date from the log without shutting down the server or causing it to lose it's open file handle to the log file. Currently I use the following on the command line successfully:
grep 19/May access > access.030519;
grep -v 19/May access > temp.access; cat temp.access > access;
The data for the current day, 20/May, keeps getting written to the newly overwritten access file. I'm guessing this works because the cat temp.access>access occurs so quickly that it grabs the inode just released, which is the same inode the access file was using before the redirect overwrote it. Anyway, I would like to automate this process.
My question, is there a way to do this more safely in Perl? Should I just do the same thing in Perl using system()?
Thanks for any suggestions.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.