Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | sub cannot_show() { |
---|
7 | print "Error: Unable to detect console logfile\n"; |
---|
8 | print "(Note: This only works if arb was started via the script 'arb')\n"; |
---|
9 | die "\n"; |
---|
10 | } |
---|
11 | |
---|
12 | sub show_log_with_less($) { |
---|
13 | my ($log) = @_; |
---|
14 | print "Showing $log using less..\n"; |
---|
15 | my $cmd = "less +F \"$log\""; |
---|
16 | # system($cmd)==0 || die "error executing '$cmd' (result=$?)"; # always fails when less is interrupted |
---|
17 | system($cmd); |
---|
18 | } |
---|
19 | |
---|
20 | sub main() { |
---|
21 | if (scalar(@ARGV)!=1) { |
---|
22 | die "Usage: arb_show_log.pl logname\n "; |
---|
23 | } |
---|
24 | |
---|
25 | my $logname = $ARGV[0]; |
---|
26 | my $server_log = $ENV{ARB_SERVER_LOG}; |
---|
27 | if (not defined $server_log) { |
---|
28 | print "Environment variable ARB_SERVER_LOG is not defined\n"; |
---|
29 | cannot_show(); |
---|
30 | } |
---|
31 | |
---|
32 | if ($server_log =~ /\/([^\/]+)$/o) { |
---|
33 | my $logdir = $`; |
---|
34 | my $runlog = $logdir.'/'.$logname.'.log'; |
---|
35 | if (-f $runlog) { |
---|
36 | show_log_with_less($runlog); |
---|
37 | } |
---|
38 | else { |
---|
39 | print "Expected logfile '$runlog' not found\n"; |
---|
40 | cannot_show(); |
---|
41 | } |
---|
42 | } |
---|
43 | else { |
---|
44 | print "Expected ARB_SERVER_LOG to contain a logfile name\n"; |
---|
45 | print "(contains '$server_log')\n"; |
---|
46 | cannot_show(); |
---|
47 | } |
---|
48 | } |
---|
49 | main(); |
---|
Note: See
TracBrowser
for help on using the repository browser.