How to wait for the program to start, and then its background?

I have a program that I am writing a script for /etc/init.d.

The problem is that the program does not deconstruct itself . It takes 5 seconds to start it, and when it is initialized, it prints the line ("Start OK") to stdout.

I want to create a script that will start the process, wait for a while when the line appears, and then continue the script, indicating failure or success (the line is found).

Obviously this does not work as I want.

daemon $PROGRAM &

Instead

(./proc > some_output) &
poll_output_for "Started OK" 10 secs or die
+3
source share
2 answers

, expect, - : . http://expect.sourceforge.net/ http://en.wikipedia.org/wiki/Expect. , . Ubuntu apt-get install expect.

a script :

#/usr/bin/env /bin/bash
# daemon.sh

sleep 2
echo Started OK
while :; do sleep 1; echo '.' >> daemon.log; done

... script, , :

#!/usr/bin/env /usr/bin/expect

spawn -ignore SIGHUP ./daemon.sh
expect "Started OK"

, " OK". , daemon SIGHUP, , . (watch cat daemon.log), .

, , . man- .

+2

, 5 , . , , - "Started OK".

, , , , - :

$prog | tee $prog_out_file
while true
do
    sleep 2
    grep -q "Started Ok" $prog_out_file && break
done
# Continue here...

, , "Started Ok", .

+1

All Articles