4

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;
export ROOT_URL=$ROOT_URL;
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

1 Answers1

7

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 
fi
fede.evol
  • 1,946