ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a good kick to get me started creating a bash/perl script to count the number of lines seen in a given 10 minute window. (And if there is a name for doing that, it may help my searching)
I will be parsing though various Apache logs, so the time format is
[10/Oct/2009:13:55:36 -0500]
To further throw a wrench in the cogs, I also cannot assume that the log file time will always be in order. Logs may go Monday, Wednesday, Tuesday, Thursday... etc.
Any help, or directions to other posts would be greatly appreciated!
if you want to run something automatically, or to "schedule" something, you probably want to use "cron". see this link http://en.wikipedia.org/wiki/Cron#Operators, it gives an example of how to run a script every 5 minutes so you should be able to easily modify it for your needs. all thats left is to write the script!
for counting the number of lines, you probably know of the "wc" program. if you need to filter out messages before counting the number of lines, ie "only messages from the last 10 minutes", then youll have to do some parsing/filtering (regex, grep, whatever).
im not sure what you mean by your last statement. my guess is you may see the following lines back to back:
of course these 2 lines dont happen within a 10 minute interval, so you have to write the logic for that. i would recommend a scripting language like perl to do the majority of your work, as it will be easier to handle this logic in perl rather than in some bash script (however i am biased towards perl).
let us know after you get something started and have some code that isnt working or if you still arent sure of where to start.
I need a good kick to get me started creating a bash/perl script to count the number of lines seen in a given 10 minute window. (And if there is a name for doing that, it may help my searching)
I will be parsing though various Apache logs, so the time format is
[10/Oct/2009:13:55:36 -0500]
To further throw a wrench in the cogs, I also cannot assume that the log file time will always be in order. Logs may go Monday, Wednesday, Tuesday, Thursday... etc.
Any help, or directions to other posts would be greatly appreciated!
More information is necessary to define the requirement before a solution is possible. For starters (to illustrate the log file names and last modification time ordering) please post the output of the following command issued from a command prompt with the Apache logs directory as the current working directory
Code:
/bin/ls -lrt | tail -30
If the Apache logs are in the same directory as many other files, please add a filename pattern after "-lrt" so only the Apache logs are listed.
"10/Oct/2009:13:55:36" looks obvious but what does the " -0500" signify and does it always begin with a space?
I don't fully understand the requirement. I have intended it as "count the lines in a log file included in a time window of 10 minutes". If this is the case, I wrote a useful awk code some time ago. After having adapted the code to the correct log time format, I ended up with:
This prints out the lines included in the 10-minutes time window defined in the BEGIN section. To simply count them, just substitute the last part of the code:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.