Good morning!
I have a variable <$user> that is being passed through, massaged, then it is written to a log file and timestamped.
What I would like to do is take that variable and create a file with the variable appended on the end so that the text file only contains timestamps. i.e. "user_status_file.$user"
I was given some code some time back and am trying to make it work, but am not having any luck.
open (TEST,">>c:/temp/argtest6.txt") or die "Failed to open argtest.tx
+t file";
# Configure the number of times and the time window using the
# following two variables.
$times = 5;
$minutes_threshold = 30;
# Parse the command line parameter - should be the user name
$count = 0;
foreach $element (@ARGV) {
#print TEST "$count,$element \n";
$count += 1;
}
$raw_user = lc ("$ARGV[7]");
my $user;
if ($raw_user =~ /^(\w+)/) {
$user = $1;
}
print TEST "$user\n";
$now = time(); #this line works
$oldest_time = $now - ($minutes_threshold*60); #this line works
$user_status_file = "C:/temp/user_status.$user";
open (USF,$user_status_file) or die "Failed to open user_status_file f
+ile";
@lines = <USF>;
close USF;
# Now, read through the lines of the file from last (most recent) to f
+irst (oldest)
# and see if n times occurred in the last m minutes.
for ( $i=$#lines; $i>=0; $i-- )
{
$timestamp = $lines[$i];
chomp $timestamp;
last if ( $timestamp < $oldest_time );
$count++;
}
print USF "$now\n";
rint USF "$now\n";
close USF;
close TEST;
The 'for' statement works, but am unable to get the user_status_file.$user created.
Is there a better way of doing this?
The purpose is so I can watch how many timestamps that particular $user has and can threshold on excessive timestamps.
Thanks,
Jonathan
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.