-
how to expect a string
this was posted on comp.unix.admin as a mistake.
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
-
Re: how to expect a string
Atropo wrote:
> this was posted on comp.unix.admin as a mistake.
>
> 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.
You could do something like this:
proc1 > log &
pid=$!
while [ -n "$pid" ]
do
sleep 1
grep "ready" log &&
kill [-whatever] "$pid" &&
pid=""
done
Regards,
Ed.
-
Re: how to expect a string
On 28 mar, 22:57, Ed Morton wrote:
> Atropo wrote:
> > this was posted on comp.unix.admin as a mistake.
>
> > 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.
>
> You could do something like this:
>
> proc1 > log &
> pid=$!
> while [ -n "$pid" ]
> do
> sleep 1
> grep "ready" log &&
> kill [-whatever] "$pid" &&
> pid=""
> done
>
> Regards,
>
> Ed.- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
Thanks for your replay ED. but I missed to say that there is a
"ready" on the log already maybe more. I need to check the new "ready"
from the time I drop the command
-
Re: how to expect a string
Atropo wrote:
> On 28 mar, 22:57, Ed Morton wrote:
>
>>Atropo wrote:
>>
>>>this was posted on comp.unix.admin as a mistake.
>>
>>>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.
>>
>>You could do something like this:
>>
>>proc1 > log &
>>pid=$!
>>while [ -n "$pid" ]
>>do
>> sleep 1
>> grep "ready" log &&
>> kill [-whatever] "$pid" &&
>> pid=""
>>done
>>
>>Regards,
>>
>> Ed.- Ocultar texto de la cita -
>>
>>- Mostrar texto de la cita -
>
>
> Thanks for your replay ED. but I missed to say that there is a
> "ready" on the log already maybe more. I need to check the new "ready"
> from the time I drop the command
>
Then remember the line number each time, e.g.:
nr=`wc -l < log`
proc1 >> log &
pid=$!
while [ -n "$pid" ]
do
sleep 1
nr=`awk -v nr="$nr" 'NR>nr && /ready/{found=1}END{print NR; exit
found}' log`
[ $? ] &&
kill [-whatever] "$pid" &&
pid=""
done
Regards,
Ed.