I want to trigger a script when port 3000 is opened by a process. The process is a Rails development server, and I just want to be notified when it finishes spinning up and port 3000 starts accepting requests.
Here is a oneliner that simply loops until the port is open. This is quick and dirty, but it might get you started.
while ! nc -z localhost 3000; do sleep 0.1; done; echo 'The server is up!'
echo statement with your action of choice.
ncis Netcat, "the Swiss-army knife for TCP/IP",
-zmeans: do not send any data, just check if the port is open,
while ! nc -z …; do sleep 0.1; done: keep checking and sleeping for one tenth of a second until the port opens up, i.e. Netcat returns with a zero (success) status.