in reply to Searching a string in running file

Hi t-rex,

If monitoring "script A" is only possible via its logfile, you could use File::Tail and monitor the file, using a regex in a similar way you would when normally reading a file (perlintro).

Now as for what the regex should look like and "report to some other script that if the run is taking place", your question doesn't contain enough information to give you a suggestion yet.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Searching a string in running file
by t-rex (Scribe) on Jul 18, 2016 at 11:37 UTC

    Hello Hauke, thanks for the prompt suggestion. i will look into using the File::tail ( i read it for the first time though) basically i want to know if the script is reading fine the below string will keep repeating with diffeent/random numbers, so in that case how should be my regex to detect that

    TPSM seed 234B8177 pass 1 x 2 x 50 errors 0 pid 34562 rulefilecycl

    thanks

      Hi t-rex,

      A single example input is not a good basis for making a regular expression, you'll need to show several examples of strings that should match and several that shouldn't, and also describe what specific information in the string you're interested in. For example, the regexes /TPSM/ and /rulefilecycl/ both match the string you provided, but I have no idea if those will also match lines you don't want to have matched.

      Also, PerlMonks is more of a place to learn, so I recommend you have a look at perlretut and try writing a regex, and feel free to ask for help here if you run into trouble (How do I post a question effectively?). The following website is also very helpful in designing a regex, here's a link to get you started: https://regex101.com/r/oX5sC6 (note that not all of Perl's features are supported, but for simple regexes like in this case it's compatible).

      Hope this helps,
      -- Hauke D

        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.