I have this script that tails a file and makes db inserts based on the parsing it does on that file. There is one file generated per day, but I would like to Continue this same process, but actually write the raw data to a file that is split up into hourly chunks.
What is a good way to tell the system that when the script starts, open a file labeled (currentTime).curr, and then at the end of the hour, rename it to just (previousHour) and open a new file (currentTime).curr, and so on...
This is what I am doing so far. db_record handles the inserts, so I figure right before there I should handle the open and close of files as well as the writing.
if ($connected) {
$timestamp = time;
if ( $timestamp < $midnight ) {
log_notice("Client : Restarting $0\n");
log_error("End Processing $src_cdr_file\n");
exec '/home/$0'
|| log_warn("Client : Could not exec $0\n");
exit 6; # Something is wrong if this exit is taken
} # End if $timestamp
log_notice("Client : Normal Termination\n");
log_error("End Processing $src_cdr_file\n\n");
exec '/usr/bin/perl', '/home/$0'
|| log_warn("Client : Could not exec $0\n");
exit 7; # Something is wrong if this exit is taken
} # End if $connected
}; # End anonymous sub
print $socket "tail\n"; # Rock n Roll
open( STDOUT, "> /dev/null" );
# Begin processing records
while ( defined( my $line = <$socket> ) ) {
if ($recover_mode) { $rec_num++; }
db_record( $sth, $line, $recover_from );
}
Something I was thinking about though was the fact sometimes it may not hit right on the HH:MM:00 and not cut the files appropriately. 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.