Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to script check port: the first check port open or close If port close.after check PID for service on port.If exist PID, kill PID, restart service have message on file log.

share|improve this question
What have you tried thus far, what do you mean by "check port" ? If the port is closed how can you get the services PID? If you provide a more precise question, I can probably help you - conceptually what you are trying to do can be done with tools like "logger" for logging, netcat to check if a port is open or fuser to check the process ID associated with a port, but its hard to put these together without knowing the service, as it appears you are asking to "test for a negative", and thus you can't get some information you need from the negative result and need to look elsewhere for it. – davidgo Sep 11 '13 at 5:59
i think Port close but PID can exist because service hang.:D – Gato Sep 11 '13 at 6:38
Surely the solution would be to check if the service is working (if its TCP you could use nc (netcat), and then if its not working send a command to "killall" the process ? – davidgo Sep 11 '13 at 8:26
i was find tutorial in… but not check PID and kill service. – Gato Sep 11 '13 at 9:14

You must log in to answer this question.

Browse other questions tagged .