Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Hi I have a bash script that needs a conditional execution of a few lines of code based on whether port 80 is already in use:

sudo git fetch origin;
sudo git checkout master;
sudo git pull;

--- if port 80 open

echo Starting Meteor;
export LC_ALL=C;
sudo meteor --port 80;

--- else

echo Meteor already running;

Then as a cherry on the top since Meteor is a long running process, how do i get it to run in the background and exit the script? (I've tried nohup, &, but i have no idea what the best practice is?)

Thanks so much

share|improve this question
Do you mean it's making a connection to port 80 or if the computer is already listening on port 80? – Daniel Chateau Mar 19 '14 at 15:23
up vote 3 down vote accepted

You could use:

netstat -ln | grep ":80 "

If the return code ($?) is 0 then something is on port :80, otherwise not. So for example:

netstat -ln | grep ":80 " 2>&1 > /dev/null 
if [ $? -eq 1 ]; then   
     ... your code here 
share|improve this answer
+1 but you'll want grep ':80\>' so you don't match ":8080" for instance – glenn jackman Mar 19 '14 at 15:44
And the 2nd part? How to get the "Your code here" to execute in background? simply "Your code here &" ? – Alasdair P Mar 19 '14 at 17:02
gleen: I've put a space in the string after 80 (":80 ") not to match 80xx, tried and seemed to work :) – fede.evol Mar 20 '14 at 6:43
Alasdair: yep just put a &. If the terminal may get closed (that is you run it manually in the shell and then close it) then nohup may be usefull since will keep the process running also in that case. – fede.evol Mar 20 '14 at 6:44

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.