I need a script for unix Aix to see if the follwoing ports area available or not (a list)

LindaC
LindaC used Ask the Experts™
on
Hi experts.

I need a script that will provide a list to see if the following ports area available or not:


Ensure that the ports you assign (within the given range) to the
following components are free and available:
¦ Admin Server HTTP SSL Port = 7101 - 7200
¦ Enterprise Manager Upload HTTP Port = 4889 - 4898
¦ Enterprise Manager Upload HTTP SSL Port = 1159, 4899 - 4908
¦ Enterprise Manager Central Console HTTP Port = 7788 - 7798
¦ Enterprise Manager Central Console HTTP SSL Port = 7799 -
7809
¦ Oracle Management Agent Port = 3872, 1830 - 1849
To verify if a port is free, run the following command:
¦ On Unix:
netstat -anp | grep <port no>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013
Commented:
Try something like this.

Add more "checkport FROM TO" lines as needed, where TO defaults to FROM if omitted.

#!/bin/ksh
function checkport {
PF=$1
PT=${2:-$PF}
while [[ $PF -le $PT ]] ; do
INU=$(netstat -an |grep "."${PF})
[[ -z $INU ]] && echo "Port $PF is free" || echo "$INU"
((PF+=1)); done
}

checkport 7101 7200
checkport 4889 4898
checkport 1159
checkport 4899 4908
checkport 7788 7798
checkport 7799 7809
checkport 3872
checkport 1830 1849

Author

Commented:
It ran ok, but I don't have a log to see.
Most Valuable Expert 2013
Top Expert 2013

Commented:
Well,

why dont you redirect the output to a log, like

scriptname > /path/to/logfile

Sorry, I really didn't assume I had to tell you such things.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
Oh! That's what stress does!
How can I ...

Thanks a lot as always!

Author

Commented:
Thank you
Most Valuable Expert 2013
Top Expert 2013

Commented:
Hi Linda,

thx for the points!

Please note these small changes in the script.
They will make the results more accurate,
and you can (but don't have to) put a hypen (-) between start and end port.

wmp

#!/bin/ksh
function checkport {
set $(echo "$@" | tr "-" " ")
PF=$1
PT=${2:-$PF}
while [[ $PF -le $PT ]] ; do
INU=$(netstat -an |grep -F ".${PF} ")
[[ -z $INU ]] && echo "Port $PF is free" || echo "$INU"
((PF+=1)); done
}

checkport 7101-7200
checkport 4889 4898
checkport 1159
checkport 4899-4908
checkport 7788 7798
checkport 7799-7809
checkport 3872
checkport 1830 1849

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial