Please complete this program.

Hi All,

I need some help to complete the below script, after executing below script blank lines are coming, but i am expecting 4 digit numeric no. Please solve the issue ASAP.

function portno
{
while (true)
do
random=`echo $RANDOM | cut -c 1-4`
port=`netstat -a | grep -c $random`

if [ $port -ne 1 ];
then
        break
else
        continue
fi
done
return $port
}

port1=`portno`
port2=`portno`

echo "$port1"
echo "$port2"

Thanks in advance...

Regards,
Sridhar.

Please post the requirement, and then lets us finish it.

-ilan

Hi,

I want to generate the 4 digit numeric no two times, then i want to use them in another script, but here the above script giving blank output.

Please somebody help me to solve this problem.

Thanks,
Sridhar.

Try:

function portno
{
while (true)
do
   random=`echo ${RANDOM} | cut -c 1-4`
   port=`netstat -a | grep -c ${random}`
   if [ ${port} -ne 1 ]
   then
      break
   fi
done
echo ${random}
}

port1=`portno`
port2=`portno`

echo "$port1"
echo "$port2"

Try this :
Is this you looking for ?

.......
#return $random
portAvailable=$random
}
portno
port1=$portAvailable

portno
port2=$portAvailable

#port1=`portno`
#port2=`portno`

echo "$port1"
echo "$port2"

Thanks for ur valueable time spending to complete my script.

Its ong.kianseng is working fine.

Thanks once again.

Sridhar.