Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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!'

Replace the echo statement with your action of choice.

  • nc is Netcat, "the Swiss-army knife for TCP/IP",
  • -z means: 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.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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