Código:
#!/bin/bash
#
# script: Verifica se a porta esta livre ou ocupada
#
#
# Algum bug contacte-me obrigado.
#
# whitehatg@gmail.com
# 19/03/2006
clear
PORT=1024
while [ $PORT -ge 50000 ] || [ $PORT -le 1024 ]
do
echo -n "Ecolha a porta(Tem de ser maior que 1024 e mais pequeno que 50000): "
read -e PORT
if [ $PORT -lt 50000 ] && [ $PORT -gt 1024 ] && [ -n $PORT ]
then
TEMP=`netstat -al | grep -c ":$PORT "`
if [ $TEMP -gt 0 ]
then
echo "Esta porta esta ocupada, escolha outra"
PORT=1024
fi
else
PORT=1024
fi
done
echo "Esta porta esta livre"
Vai ser util
Vou tentar todos dias meter aqui um script ,scripts que fiz ja algum tempo e espero que vos sirva para aprender.