Added listening function.

Listening functions checks whether there exist a service listening
on specified protocol and port.
This commit is contained in:
Kamil Boratyński 2016-03-22 23:53:58 +01:00
parent 9023aaa052
commit 3e5555fb12
1 changed files with 25 additions and 0 deletions

View File

@ -49,6 +49,7 @@
# IsWorldExecutable Check if a file is world executable
# IsWorldReadable Check if a file is world readable
# IsWorldWritable Check if a file is world writable
# IsTcpUdpListening Check if machine is listening on specified protocol and port
# LogText Log text strings to logfile, prefixed with date/time
# ParseNginx Parse nginx configuration lines
# Progress Show progress on screen
@ -118,6 +119,30 @@
}
################################################################################
# Name : IsTcpUdpListening()
# Description : Check if machine is listening on specified protocol and port
# Returns : 0 or 1
################################################################################
IsTcpUdpListening()
{
LISTENING=0
if [ $# -eq 2 ] && [ $1 = "TCP" -o $1 = "UDP" ]; then
LogText "Test: find service listening on $1:$2"
FIND=`lsof -i${1} -s${1}:LISTEN | grep "${2}" | wc -l`
if [ ! "${FIND}" = "" ]; then
LogText "Result: found service listening on $1:$2"
LISTENING=1
else
LogText "Result: did not find service listening on $1:$2"
fi
else
ReportException ${TEST_NO} "Error in function call to IsTcpUdpListening"
return 1
fi
}
################################################################################
# Name : CheckItem()
# Description : Check if a specific item exists in the report