Skip to content

Instantly share code, notes, and snippets.

@itang
Created February 11, 2017 11:13
Show Gist options
  • Save itang/342ba16bd03005044ea6a0bebac7eda5 to your computer and use it in GitHub Desktop.
Save itang/342ba16bd03005044ea6a0bebac7eda5 to your computer and use it in GitHub Desktop.
#!/bin/bash
port=$1
if [ "$port" = "" ]; then
echo "please input the port for check!"
exit 1
fi
max_attempts=10
attempts=0
echo "lsof -i $port"
while [ "`lsof -i TCP:$port`" != "" ]
do
echo "alive..."
if [ "$attempts" = "$max_attempts" ]; then
./stop force
exit 0
fi
echo "try $attempts, sleep 1"
sleep 1
(( attempts += 1))
done
echo "$port not alive!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment