-1

I'm looking to run some SQL statements into a mssql database before the DB is started (this is happening as part of a docker RUN step). From what I can tell, the only way to do this is to start the server in the background, wait for it to come up, then run the sql file, then kill the server.

Based on this question I have the following which works fine:

/opt/mssql/bin/sqlservr & sleep 10 && /opt/mssql-tools/bin/sqlcmd -i whatever.sql && pkill sqlservr

The problem is that the sleep 10 is a bit brittle if the server is slow to start, or adds delay if it is quick to start. Is there a way that I can replace sleep 10 part to something which monitors the stdout of the /opt/mssql/bin/sqlservr command and blocks until a particular log line is matched?

0

I think this solution works based on this super user answer:

( /opt/mssql/bin/sqlservr & ) | grep -q "Service Broker manager has started" && /opt/mssql-tools/bin/sqlcmd -i whatever.sql && pkill sqlservr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.