How to expect a string on a log file - Unix

This is a discussion on How to expect a string on a log file - Unix ; Sorry, maybe the subject was somehow vague. what I want is . I had a process (proc1) with that writes to a log. when this process came up it writes a "ready" on the log , about 1 or 2 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to expect a string on a log file

  1. How to expect a string on a log file

    Sorry, maybe the subject was somehow vague.
    what I want is .

    I had a process (proc1) with that writes to a log. when this process
    came up it writes a "ready" on the log , about 1 or 2 mins later. I
    would like to raise another instance (proc2), check the log and wait
    for the "ready" string, then kill the old proc1. don't know how to get
    out of "tail -f log|grep ready" when it appears. I treated with
    "expect" but culdn't find an easy help on it, and to be honest don't
    understand a bit of it. Hope you give me some advice or better
    approach.

    TIA


  2. Re: How to expect a string on a log file

    "Atropo" writes:

    > Sorry, maybe the subject was somehow vague.
    > what I want is .
    >
    > I had a process (proc1) with that writes to a log. when this process
    > came up it writes a "ready" on the log , about 1 or 2 mins later. I
    > would like to raise another instance (proc2), check the log and wait
    > for the "ready" string, then kill the old proc1. don't know how to get
    > out of "tail -f log|grep ready" when it appears. I treated with
    > "expect" but culdn't find an easy help on it, and to be honest don't
    > understand a bit of it. Hope you give me some advice or better
    > approach.


    I don't know the answer to your question, but I'm thinking there
    simply has to be a better way to do inter-process communication here
    than scraping log files with tail and grep and killing processes.

    Are both of these running on the same box? What language(s) are you
    constrained to if any? This may be a useful opportunity to learn
    Perl.

    --
    Todd H.
    http://www.toddh.net/

  3. Re: How to expect a string on a log file

    On 28 mar, 13:36, comph...@toddh.net (Todd H.) wrote:
    > "Atropo" writes:
    > > Sorry, maybe the subject was somehow vague.
    > > what I want is .

    >
    > > I had a process (proc1) with that writes to a log. when this process
    > > came up it writes a "ready" on the log , about 1 or 2 mins later. I
    > > would like to raise another instance (proc2), check the log and wait
    > > for the "ready" string, then kill the old proc1. don't know how to get
    > > out of "tail -f log|grep ready" when it appears. I treated with
    > > "expect" but culdn't find an easy help on it, and to be honest don't
    > > understand a bit of it. Hope you give me some advice or better
    > > approach.

    >
    > I don't know the answer to your question, but I'm thinking there
    > simply has to be a better way to do inter-process communication here
    > than scraping log files with tail and grep and killing processes.
    >
    > Are both of these running on the same box? What language(s) are you
    > constrained to if any? This may be a useful opportunity to learn
    > Perl.
    >
    > --
    > Todd H.http://www.toddh.net/


    Thanks Todd for your reply..
    well as you could notice, I'm a newbie, so this inter-process comm.
    could lead me to lost.
    the process is in same box.


  4. Re: How to expect a string on a log file

    "Atropo" writes:
    > On 28 mar, 13:36, comph...@toddh.net (Todd H.) wrote:
    > > "Atropo" writes:
    > > > Sorry, maybe the subject was somehow vague.
    > > > what I want is .

    > >
    > > > I had a process (proc1) with that writes to a log. when this process
    > > > came up it writes a "ready" on the log , about 1 or 2 mins later. I
    > > > would like to raise another instance (proc2), check the log and wait
    > > > for the "ready" string, then kill the old proc1. don't know how to get
    > > > out of "tail -f log|grep ready" when it appears. I treated with
    > > > "expect" but culdn't find an easy help on it, and to be honest don't
    > > > understand a bit of it. Hope you give me some advice or better
    > > > approach.

    > >
    > > I don't know the answer to your question, but I'm thinking there
    > > simply has to be a better way to do inter-process communication here
    > > than scraping log files with tail and grep and killing processes.
    > >
    > > Are both of these running on the same box? What language(s) are you
    > > constrained to if any? This may be a useful opportunity to learn
    > > Perl.
    > >
    > > --
    > > Todd H.http://www.toddh.net/

    >
    > Thanks Todd for your reply..
    > well as you could notice, I'm a newbie, so this inter-process comm.
    > could lead me to lost.
    > the process is in same box.


    interprocess communication is simply a way for two separate processes
    to, well, communicate with each other about stuff getting done like
    this. Basically you need process2 to know when process1 has
    finished with something to process 2 can do it's thing.

    If you can describe conceptually what you're attempting to accomplish
    perhaps folks can suggest how they'd tackle the same problem. Are you
    constrained to only using bash shell commands, or are you free to use
    perl, python, or whatever language might be available?

    --
    Todd H.
    http://www.toddh.net/

  5. Re: How to expect a string on a log file

    "Atropo" writes:

    > Sorry, maybe the subject was somehow vague.
    > what I want is .
    >
    > I had a process (proc1) with that writes to a log. when this process
    > came up it writes a "ready" on the log , about 1 or 2 mins later. I
    > would like to raise another instance (proc2), check the log and wait
    > for the "ready" string, then kill the old proc1. don't know how to get
    > out of "tail -f log|grep ready" when it appears. I treated with
    > "expect" but culdn't find an easy help on it, and to be honest don't
    > understand a bit of it. Hope you give me some advice or better
    > approach.


    Another approach, that would still be probably a horrible hack is to
    schedule a script to run in cron (man cron) to run every so often (as
    appopriate to the duration of proc1) to grep the log file file.

    The script could be (syntax left as an exercise to the reader)

    if /tmp/process1.processid.txt exists (assuming process1 is modified
    to write this file and put its unix process id in it)

    if ( /bin/grep ready /tmp/logfile )
    kill `cat /tmp/process1.processid.txt`
    else
    exit 0


    Now this is a horrible horrible hack filled with all sorts of
    potential for error, tremendous inefficiency looking at hte whole log
    file every time, no handling of multiple process1's running, or if the
    file isn't there etc, so there are a million better ways to do this,
    but this is one alternative to your original question.

    crontab -e is the command you'd execute to add a line in crontab
    for this script to run. crontab syntax is a bit wacky so work from an
    example.


    --
    Todd H.
    http://www.toddh.net/

+ Reply to Thread