Advertisement
josacar

Get lines/s from file v0.1

Sep 29th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 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. // char buf[32768];
  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.  lseek( fd, 0, SEEK_END);
  15.  
  16.  
  17. for ( ;; ) {
  18.  
  19.   buflen = read(fd, buf, sizeof(buf));
  20.  
  21.   for ( i=0; i<sizeof(buf);i++){
  22.     if ( buf[i] == '\n' ) {
  23.         lineas++;
  24.     }
  25.   }
  26.  
  27.  
  28.  if ( buflen > 0 ){
  29. //    printf("%s",buf);
  30.         printf("Lineas/s: %d\n", lineas);
  31.         lineas = 0;
  32.  }
  33.  
  34.  lseek(fd, sizeof(buf), SEEK_CUR);
  35.  
  36.  sleep ( 1 );
  37.  
  38. }
  39.  
  40. close(fd);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement