I have the following bash script:
#!/bin/bash
set -m
./cloud_sql_proxy -instances=[project-id]:[region]:[instance-id]=tcp:5432 -credential_file=serviceaccount.json &
sleep 5
node app.js
First, I want the cloud_sql_proxy command to run. After 5 seconds, I also want the node command to run. The first command (cloud_sql_proxy) is a command that keeps running, so a wait does not work here (it keeps waiting).
When the cloud_sql_proxy command is 'ready', it outputs "Ready for new connections". Is there anyway I can "capture" this output, check if it "Ready for new connections", and if so, execute the second command (node)? In that way, I do not longer need the sleep 5 and I'm sure the node command is not running if there is a problem with the cloud_sql_proxy command.
cloud_sql_proxyto a file and thengrepthat file for the required output to check.