Advertisement
josacar

Get lines/s from file v0.2

Sep 30th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4.  
  5. int main( int argc, char *argv[] ) {
  6.  
  7.  char buf[1024];
  8.  int fd, buflen,lineas=0,i=0;
  9.  
  10.  
  11.  fd = open("/var/log/snort/alert.fast",O_RDONLY);
  12.  
  13.  lseek( fd, 0 - sizeof(buf), SEEK_END);
  14.  
  15.  
  16. for ( ;; ) {
  17.  
  18.   buflen = read(fd, buf, sizeof(buf));
  19.  
  20.   for ( i=0; i<buflen;i++){
  21.     if ( buf[i] == '\n' ) {
  22.         lineas++;
  23.     }
  24.   }
  25.  
  26.  
  27.  if ( buflen > 0 ){
  28. //    printf("%s",buf);
  29.         printf("Lineas/s: %d\tBuffer: %d\r", lineas,buflen);
  30.         fflush(stdout);
  31.         lineas = 0;
  32.  }
  33.  
  34.  lseek(fd, buflen, SEEK_CUR);
  35.  
  36.  sleep ( 1 );
  37.  
  38. }
  39.  
  40. close(fd);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement