Salome HOME
PR: merge from branch BR_auto_V310 tag mergefrom_OCC_development_for_3_2_0a2_10mar06
[modules/kernel.git] / bin / appliskel / searchFreePort.sh
1 #!/bin/bash
2
3 # --- define port for CORBA naming service
4
5 searchFreePort() {
6     echo -n "Searching for a free port for naming service: "
7     NSPORT=2810
8     export NSPORT
9     local limit=$NSPORT
10     let limit=limit+100
11     while [ 1 ]
12     do
13         aRes=`netstat -ltn | grep -E :${NSPORT}`
14         if [ -z "$aRes" ]; then
15             echo ${NSPORT} - Ok
16             local myhost=`hostname`
17             OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg
18             export OMNIORB_CONFIG
19             export NSPORT
20             NSHOST=${myhost}
21             export NSHOST
22             local initref="NameService=corbaname::"`hostname`":$NSPORT"
23             #echo "ORBInitRef $initref" > $OMNIORB_CONFIG
24             echo "InitRef = $initref" > $OMNIORB_CONFIG
25             LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg
26             export LAST_RUNNING_CONFIG
27             rm ${LAST_RUNNING_CONFIG}
28             ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG}
29             break
30         fi
31         echo -n "${NSPORT} "
32         if [[ $NSPORT -eq $limit ]] ; then
33             echo
34             echo "Can't find a free port to launch omniNames"
35             echo "Try to kill the running servers and then launch SALOME again."
36             exit
37         fi
38         let NSPORT=NSPORT+1
39     done
40 }
41