Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash resolve service name

Tags:

linux

bash

netcat

As part of a start script I need to check to see if a particular TCP service is actually up and running. By reading a config file I know what the target host and service name is. I intended to use nc to send a sample request to this service, because I know how to use it and it scripts well, the problem is that nc cannot resolve the service name in my config to a port number...

Which brings me to my (2-part) question: Is there a bash built-in or commonly distributed utility (would be part or a RHEL 5 distro) which can resolve the service name to a port number? Is there a simple utility other than netcat which I could use in my script instead?

like image 572
Hoons Avatar asked Aug 16 '26 00:08

Hoons


1 Answers

getent is what you want.

For instance: getent services ftp

You'll need to parse the output anyway, but you have the port.

like image 142
fge Avatar answered Aug 18 '26 16:08

fge