Howto check open ports of a specific tomcat java instanceJava and Tomcat issueJava: Tomcat slow serving static files?Java and Tomcat - where to put jars?Tomcat/java tuning books for sysadminsRun Tomcat and Java on Amazon EC2 Instanceec2, ping and security settingsTomcat ClassNotFoundException after switching from openjdk to sun javaActiveMQ - “Cannot send, channel has already failed” every 2 seconds?Tomcat & Java not listening on IPv6Tomcat Java error (Java/Tomcat noob)
How do I properly use a function under a class?
Nth term of Van Eck Sequence
Is it a good security practice to force employees hide their employer to avoid being targeted?
Harley Davidson clattering noise from engine, backfire and failure to start
Why would a car salesman tell me not to get my credit pulled again?
How to deal with an excess of white-space in a CRM UI?
Which are the methodologies for interpreting Vedas?
Why is my Taiyaki (Cake that looks like a fish) too hard and dry?
Must I use my personal social media account for work?
My mom's return ticket is 3 days after I-94 expires
Remove the small black rectangle that appears at the end of environment
Someone who is granted access to information but not expected to read it
Is it true that "only photographers care about noise"?
Do Veracrypt encrypted volumes have any kind of brute force protection?
Fastest way from 8 to 7
Print "N NE E SE S SW W NW"
What publication claimed that Michael Jackson died in a nuclear holocaust?
Does WiFi affect the quality of images downloaded from the internet?
Generate parentheses solution
Boss making me feel guilty for leaving the company at the end of my internship
What do I need to do, tax-wise, for a sudden windfall?
How (un)safe is it to ride barefoot?
Are athlete's college degrees discounted by employers and graduate school admissions?
How can I find out about the game world without meta-influencing it?
Howto check open ports of a specific tomcat java instance
Java and Tomcat issueJava: Tomcat slow serving static files?Java and Tomcat - where to put jars?Tomcat/java tuning books for sysadminsRun Tomcat and Java on Amazon EC2 Instanceec2, ping and security settingsTomcat ClassNotFoundException after switching from openjdk to sun javaActiveMQ - “Cannot send, channel has already failed” every 2 seconds?Tomcat & Java not listening on IPv6Tomcat Java error (Java/Tomcat noob)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
For the moment I've managed to do it with:
root@server:~# for i in $(netstat -lp | grep java | awk 'print $7' | awk -F '/' 'print $1' | sort | uniq); do ap=$(ps p $i | grep -v PID | grep activemq | awk 'print $1'); done; netstat -lp | grep $ap
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
It checks all process IDs belonging to open network ports, checks whether or not it is a tomcat instance "activemq".
Any better suggestions?
bash tomcat java shell activemq
add a comment |
For the moment I've managed to do it with:
root@server:~# for i in $(netstat -lp | grep java | awk 'print $7' | awk -F '/' 'print $1' | sort | uniq); do ap=$(ps p $i | grep -v PID | grep activemq | awk 'print $1'); done; netstat -lp | grep $ap
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
It checks all process IDs belonging to open network ports, checks whether or not it is a tomcat instance "activemq".
Any better suggestions?
bash tomcat java shell activemq
add a comment |
For the moment I've managed to do it with:
root@server:~# for i in $(netstat -lp | grep java | awk 'print $7' | awk -F '/' 'print $1' | sort | uniq); do ap=$(ps p $i | grep -v PID | grep activemq | awk 'print $1'); done; netstat -lp | grep $ap
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
It checks all process IDs belonging to open network ports, checks whether or not it is a tomcat instance "activemq".
Any better suggestions?
bash tomcat java shell activemq
For the moment I've managed to do it with:
root@server:~# for i in $(netstat -lp | grep java | awk 'print $7' | awk -F '/' 'print $1' | sort | uniq); do ap=$(ps p $i | grep -v PID | grep activemq | awk 'print $1'); done; netstat -lp | grep $ap
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
It checks all process IDs belonging to open network ports, checks whether or not it is a tomcat instance "activemq".
Any better suggestions?
bash tomcat java shell activemq
bash tomcat java shell activemq
edited Jul 19 '11 at 16:52
hmontoliu
3,12331623
3,12331623
asked Jul 19 '11 at 15:05
Joe NazzJoe Nazz
146118
146118
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
for i in $(ps aux | awk '/activemq/ print $2' | sort -gu); do netstat -lp | grep $i; done
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
was shorter but it calls netstat multiple times.
add a comment |
This one will be a bit more terse; it checks which are the pids of processes named ".*activemq.*
" and after that checks their opened ports:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2')
You can add a uniq filter if you need to:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)
EDITED BASED ON JOE's COMMENTS:
Joe Nazz wrote:
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..." –
You are right, If there are several processes we need to work a bit more in our grep's regexp expression.
So in order to keep my run-netstat-just-once command, the expression should be something similar to:
~# netstat -lp | grep $(ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"')
The command creates a regexp to match each pid of apache (I'm using apache2 as a multi instance process to match your needs). As you'll see in the following expression, the regexp created tries to match every single pid of apache:
~# ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"'
(7335|7336|7337|7338|7339|8733|8744|13418|13421|23126)
– Joe Nazz wrote:
[...] But what does the single 'a' in the brackets mean? –
About your question related of why I used the [a] in the regexp, it is a very old trick to avoid matching the process created by the regexp it self. The following example is self explanatory:
~# ps aux | grep foo
root 10932 0.0 0.0 9608 868 pts/0 S+ 11:42 0:00 grep foo
~# ps aux | grep "[f]oo"
~#
PS: if you feel this answer was helpful please don't leave unvoted
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
add a comment |
This retrieves "activemq" pids, tests that one was returned, runs netstat once.
pids=`ps -eo 'pid,args' | awk '/activemq/ && !/awk/ print $1'`
test -n "$pids" && netstat -lp | egrep -w "(`echo $pids | tr ' ' '|'`)"
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f291870%2fhowto-check-open-ports-of-a-specific-tomcat-java-instance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
for i in $(ps aux | awk '/activemq/ print $2' | sort -gu); do netstat -lp | grep $i; done
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
was shorter but it calls netstat multiple times.
add a comment |
for i in $(ps aux | awk '/activemq/ print $2' | sort -gu); do netstat -lp | grep $i; done
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
was shorter but it calls netstat multiple times.
add a comment |
for i in $(ps aux | awk '/activemq/ print $2' | sort -gu); do netstat -lp | grep $i; done
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
was shorter but it calls netstat multiple times.
for i in $(ps aux | awk '/activemq/ print $2' | sort -gu); do netstat -lp | grep $i; done
tcp 0 0 localhost:32000 *:* LISTEN 23059/java
tcp6 0 0 HPM.DMZ:61616 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:8161 [::]:* LISTEN 23059/java
tcp6 0 0 [::]:36168 [::]:* LISTEN 23059/java
was shorter but it calls netstat multiple times.
answered Jul 20 '11 at 12:33
Joe NazzJoe Nazz
146118
146118
add a comment |
add a comment |
This one will be a bit more terse; it checks which are the pids of processes named ".*activemq.*
" and after that checks their opened ports:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2')
You can add a uniq filter if you need to:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)
EDITED BASED ON JOE's COMMENTS:
Joe Nazz wrote:
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..." –
You are right, If there are several processes we need to work a bit more in our grep's regexp expression.
So in order to keep my run-netstat-just-once command, the expression should be something similar to:
~# netstat -lp | grep $(ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"')
The command creates a regexp to match each pid of apache (I'm using apache2 as a multi instance process to match your needs). As you'll see in the following expression, the regexp created tries to match every single pid of apache:
~# ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"'
(7335|7336|7337|7338|7339|8733|8744|13418|13421|23126)
– Joe Nazz wrote:
[...] But what does the single 'a' in the brackets mean? –
About your question related of why I used the [a] in the regexp, it is a very old trick to avoid matching the process created by the regexp it self. The following example is self explanatory:
~# ps aux | grep foo
root 10932 0.0 0.0 9608 868 pts/0 S+ 11:42 0:00 grep foo
~# ps aux | grep "[f]oo"
~#
PS: if you feel this answer was helpful please don't leave unvoted
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
add a comment |
This one will be a bit more terse; it checks which are the pids of processes named ".*activemq.*
" and after that checks their opened ports:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2')
You can add a uniq filter if you need to:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)
EDITED BASED ON JOE's COMMENTS:
Joe Nazz wrote:
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..." –
You are right, If there are several processes we need to work a bit more in our grep's regexp expression.
So in order to keep my run-netstat-just-once command, the expression should be something similar to:
~# netstat -lp | grep $(ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"')
The command creates a regexp to match each pid of apache (I'm using apache2 as a multi instance process to match your needs). As you'll see in the following expression, the regexp created tries to match every single pid of apache:
~# ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"'
(7335|7336|7337|7338|7339|8733|8744|13418|13421|23126)
– Joe Nazz wrote:
[...] But what does the single 'a' in the brackets mean? –
About your question related of why I used the [a] in the regexp, it is a very old trick to avoid matching the process created by the regexp it self. The following example is self explanatory:
~# ps aux | grep foo
root 10932 0.0 0.0 9608 868 pts/0 S+ 11:42 0:00 grep foo
~# ps aux | grep "[f]oo"
~#
PS: if you feel this answer was helpful please don't leave unvoted
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
add a comment |
This one will be a bit more terse; it checks which are the pids of processes named ".*activemq.*
" and after that checks their opened ports:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2')
You can add a uniq filter if you need to:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)
EDITED BASED ON JOE's COMMENTS:
Joe Nazz wrote:
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..." –
You are right, If there are several processes we need to work a bit more in our grep's regexp expression.
So in order to keep my run-netstat-just-once command, the expression should be something similar to:
~# netstat -lp | grep $(ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"')
The command creates a regexp to match each pid of apache (I'm using apache2 as a multi instance process to match your needs). As you'll see in the following expression, the regexp created tries to match every single pid of apache:
~# ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"'
(7335|7336|7337|7338|7339|8733|8744|13418|13421|23126)
– Joe Nazz wrote:
[...] But what does the single 'a' in the brackets mean? –
About your question related of why I used the [a] in the regexp, it is a very old trick to avoid matching the process created by the regexp it self. The following example is self explanatory:
~# ps aux | grep foo
root 10932 0.0 0.0 9608 868 pts/0 S+ 11:42 0:00 grep foo
~# ps aux | grep "[f]oo"
~#
PS: if you feel this answer was helpful please don't leave unvoted
This one will be a bit more terse; it checks which are the pids of processes named ".*activemq.*
" and after that checks their opened ports:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2')
You can add a uniq filter if you need to:
netstat -lp | grep $(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)
EDITED BASED ON JOE's COMMENTS:
Joe Nazz wrote:
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..." –
You are right, If there are several processes we need to work a bit more in our grep's regexp expression.
So in order to keep my run-netstat-just-once command, the expression should be something similar to:
~# netstat -lp | grep $(ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"')
The command creates a regexp to match each pid of apache (I'm using apache2 as a multi instance process to match your needs). As you'll see in the following expression, the regexp created tries to match every single pid of apache:
~# ps aux | awk '/[a]pache/ "$2 END sub(/^../,"",a); print "("a")"'
(7335|7336|7337|7338|7339|8733|8744|13418|13421|23126)
– Joe Nazz wrote:
[...] But what does the single 'a' in the brackets mean? –
About your question related of why I used the [a] in the regexp, it is a very old trick to avoid matching the process created by the regexp it self. The following example is self explanatory:
~# ps aux | grep foo
root 10932 0.0 0.0 9608 868 pts/0 S+ 11:42 0:00 grep foo
~# ps aux | grep "[f]oo"
~#
PS: if you feel this answer was helpful please don't leave unvoted
edited Jul 23 '11 at 9:57
community wiki
7 revs
hmontoliu
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
add a comment |
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
Nice, thx! But what does the single 'a' in the brackets mean?
– Joe Nazz
Jul 20 '11 at 12:17
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
It doesn't work. The result of """$(ps aux | awk '/[a]ctivemq/ print $2' | sort -u)""" are multiple lines, that grep cannot recognize. It comes "No such file or dir..."
– Joe Nazz
Jul 20 '11 at 12:25
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
See my post edition. Answers both of your comments
– hmontoliu
Jul 23 '11 at 9:46
add a comment |
This retrieves "activemq" pids, tests that one was returned, runs netstat once.
pids=`ps -eo 'pid,args' | awk '/activemq/ && !/awk/ print $1'`
test -n "$pids" && netstat -lp | egrep -w "(`echo $pids | tr ' ' '|'`)"
add a comment |
This retrieves "activemq" pids, tests that one was returned, runs netstat once.
pids=`ps -eo 'pid,args' | awk '/activemq/ && !/awk/ print $1'`
test -n "$pids" && netstat -lp | egrep -w "(`echo $pids | tr ' ' '|'`)"
add a comment |
This retrieves "activemq" pids, tests that one was returned, runs netstat once.
pids=`ps -eo 'pid,args' | awk '/activemq/ && !/awk/ print $1'`
test -n "$pids" && netstat -lp | egrep -w "(`echo $pids | tr ' ' '|'`)"
This retrieves "activemq" pids, tests that one was returned, runs netstat once.
pids=`ps -eo 'pid,args' | awk '/activemq/ && !/awk/ print $1'`
test -n "$pids" && netstat -lp | egrep -w "(`echo $pids | tr ' ' '|'`)"
answered Jul 31 '11 at 2:32
brightlancerbrightlancer
1211
1211
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f291870%2fhowto-check-open-ports-of-a-specific-tomcat-java-instance%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown