Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Check unused ports in a given range and assign an open one

Shell Programming and Scripting


Tags
korn shell script, linux 6.0, netstat, port number.

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 01-10-2017
general_franco general_franco is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 26 March 2017, 7:45 PM EDT
Posts: 34
Thanks: 15
Thanked 0 Times in 0 Posts
Hi Robin. These aren't database listeners. As mentioned earlier, they're gateway listeners and a listener for MSSQL has to be configured differently to one for say DRDA. They cannot be shared.
Sponsored Links
    #9  
Old Unix and Linux 01-10-2017
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 24 March 2017, 12:41 PM EDT
Location: Lancashire, UK
Posts: 3,052
Thanks: 1,280
Thanked 583 Times in 528 Posts
I don't see MSSQL mentioned earlier and I missed the point about them being Gateway as opposed to plain database listeners, but how about this suggestion:-
  • Select a range of ports that are free
  • Define them in /etc/services quoting the database name (DA, DB, DC, DD etc.)
  • As the listener starts, it reads /etc/services and starts on a fixed port number, reporting failures however you choose, e.g. syslog, email, sms, console, 3rd party tools etc.
That way you know the ports should be allocated to just your service. If you start them at boot, then one would think that they should still be free. if something else is grabbing one, then find out why and/or change /etc/services to move your service to a new port. It's not foolproof because not everything respects /etc/services but it's a good place to start and many network tools (e.g. netstat & lsof) do, making their output more meaningful.

You could even (if your databases are using a sequential naming system) make the port numbers obvious and predictable, e.g. DA is port 13001, DB is port 13002, etc. This would give your clients wanting to connect a consistent port to connect to.


Would that help?

Robin
The Following User Says Thank You to rbatte1 For This Useful Post:
general_franco (01-10-2017)
Sponsored Links
    #10  
Old Unix and Linux 01-10-2017
general_franco general_franco is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 26 March 2017, 7:45 PM EDT
Posts: 34
Thanks: 15
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by general_franco View Post
Hi Jim. I'd better give a bit more info. I'm generating a new listener file for a gateway from a script so I have to assign a port.
MSQL or DRDA are just examples of some of the gateways I'm using so there was no actual need to mention them specifically. The range of free ports is defined initially and they're reserved for Oracle. I just have to assign a new one when creating the gateway listener file so I'll just use netstat for that. Your point about making port numbers more obvious is a sensible approach. I'll modify my script slightly to assign ports from that defined range incrementally if possible. Thanks for your advice.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
based on range assign a value Diya123 Shell Programming and Scripting 3 08-05-2011 03:38 PM
locking down unused or unwanted ports in AIX admaix AIX 1 07-27-2010 09:38 AM
Sheel Scripting to lock 2 TCP unused ports in solaris and linux sreeramr30 Shell Programming and Scripting 2 11-01-2009 11:48 PM
filtering a range of ports out of a netstat output marcpascual Shell Programming and Scripting 1 09-30-2008 09:36 PM
Check open ports every ... MorchiuS Shell Programming and Scripting 2 08-03-2005 04:17 PM



All times are GMT -4. The time now is 12:28 AM.