分类:
2010-03-18 17:20:46
有
多个Domain部署,为了查看那些Domain运行,不得不重复的运行netstat -an
然后看端口,有时端口记不清了,就只好看config/config.xml
文件,很麻烦,于是用perl写了个小工具,自动查找运行的端口,并对照config.xml中
1 #!/usr/bin/perl
2 # to show running domains
3 # Auhtor: xaliyan
4 # Date: 11th Jul 2009
5
6 use File::Find;
7 my $domain_home="/app/bea/user_projects/domains/";
8 my @allfiles; #all files in $domain home
9 my @fullconfig; #the full path of the config.xml files
10 my @tmpfile; #the config file contents
11 my $port; #domain port
12 my $domain; #domain name
13 my $config; #basenameof config.xml file
14
15
16 find sub{push(@allfiles,$File::Find::name)},"$domain_home";
17 foreach (@allfiles) {
18 push(@fullconfig,$_) if (/config\/config.xml/);
19 }
20
21
22 foreach(@fullconfig) {
23 $config=$_;
24 s/$domain_home//g;
25 s/\/config\/config\.xml//g;
26 $domain=$_;
27 chomp($domain);
28 @tmpfile=`cat $config`;
29 foreach(@tmpfile) {
30 $port=$_ if /port/;
31 $port =~ s/\D*//g;
32 chomp;
33 }
34 $apphash{$port}=$domain;
35 }
36
37 #print $apphash{"7111"};
38
39 my @allport=`netstat -an`;
40 my @upport;
41 my $up;
42
43
44 @upport=grep(/\bLISTEN\b/i,@allport);
45 @upport=grep(!/127.0.0.1/,@upport);
46 my @running;
47 foreach (@upport) {
48 /(:\d+\s)/;
49 $up=$1;
50 $up=~s/[:|\s+]//g;
51 chomp;
52 push(@running,$up);
53 }
54 @running=sort@running;
55
56 my @ip=`/sbin/ifconfig eth0`;
57 @ip=grep(/\binet\b/,@ip);
58 foreach(@ip) {
59 /(addr:\d+\.\d+\.\d+\.\d+)/;
60 $ip=$1;
61 $ip=~ s/addr://g;
62 }
63
64 print "\nNo. DomainName Port ManageURL \n";
65 print ("-" x 60,"\n");
66 my $n=1;
67 foreach (@running) {
68 if ($apphash{$_}) {
69 # printf "%-10s \t %5s \n",$apphash{$_},$_ ;
70 printf "$n %-10s\t%5s http://%s:%s/console/\n",$apphash{$_},$_,$ip,
71 $_ ;
72 $n++;
73 }
74 }
75 print ("-" x 60,"\n");
运行结果就这样了,很方便。
No. DomainName Port ManageURL =20
------------------------------------------------------------
1 domaina 7088
2 domainb 7099
3 domainc 7101
4 domaind 7103
5 domaine 7104
6 domainf 7107
------------------------------------------------------------