in reply to Re^3: Searching a string in running file
in thread Searching a string in running file

Hi Hauke, The File::Tail can't be used because my server doesnt let us install anything , and this package is not installed on the machine, i was using the shell "tail" function but the problem with that is when the file ends this function gets hanged . Also since my requirement is to just see if that particular string gets repeated with different numbers , i can't figure out how to write a function for it because the log file is constantly be written by another script. could u give me a head start so that i can improvise and implement.

  • Comment on Re^4: Searching a string in running file

Replies are listed 'Best First'.
Re^5: Searching a string in running file
by Corion (Patriarch) on Jul 19, 2016 at 06:52 UTC
Re^5: Searching a string in running file
by haukex (Archbishop) on Jul 19, 2016 at 11:07 UTC
Re^5: Searching a string in running file
by Marshall (Canon) on Jul 19, 2016 at 16:15 UTC
    With the shell tail function, you will hit the current EOF. You cannot read past the EOF. After awhile (suitable time delay for your application), you have to do another tail in order to see additional lines that have been added. This is normal.

    Without knowing much about your particular problem (one example line is not much to go on), sometimes in this situation, all that is needed is to monitor the size of the file and just verify that it continues to grow. my $size = -s "logfile";. Of course that won't work if the program continues to grow the file in spite of being in some kind of error mode.

    Update: The system tail command should be adequate for what you need. I presume that you are only doing this once per 30-60 seconds? Or maybe even less often? Also consider whether or not a simple line "eq" string comparison is adequate (current last line not identical to the last line at the last time that we checked). It could be that you don't even need a regex? Again without more details about this log file, it is impossible to say. If you show evidence to reject my simple "check file size" suggestion, then along the way you will provide us with enough data to write a proper regex for you.