Cleaned up demos, various build fixes
[urisagit/Stem.git] / bin / demo / tail_demo
1 #!/usr/local/bin/perl -s
2
3 use lib qw(../blib/lib blib/lib);
4 use Stem::ConfigData;
5 $ENV{PATH} .= ':blib/script:../blib/script:demo:.';
6 my $xterm = Stem::ConfigData->config('xterm_path');
7 my $telnet = Stem::ConfigData->config('telnet_path');
8 $conf_path='conf:../conf';
9
10 $line_cnt = 10 ;
11 $offset = 175 ;
12 $base_off = 0 ;
13 $xskip = ( $^O eq 'solaris' ) ? 600 : 500 ;
14
15 my @children ;
16
17 my $tail_dir = 'tail' ;
18
19 $SIG{ 'INT' } = \&cleanup ;
20
21 if ( $s ) {
22
23         $ssfe = 'ssfe' ;
24         $prompt = '-prompt "Stem: "' ;
25         $echo = 'console_echo=1'
26 }
27
28 -d $tail_dir or mkdir $tail_dir, 0722 or
29                 die "can't create $tail_dir working directory" ;
30
31 foreach my $log ( qw( foo bar bar_status ) ) {
32         unlink "$tail_dir/$log.log" ;
33 }
34
35
36 foreach $cmd ( split /\n/, <<EOT ) {
37 xterm -T Archive -n Archive -geometry 80x35+0+0 -e $ssfe $prompt run_stem conf_path=$conf_path $echo archive
38 xterm -T Monitor -n Monitor -geometry 80x35+$xskip+0 -e $ssfe $prompt run_stem conf_path=$conf_path $echo monitor
39 xterm -T Tail -n Tail -geometry 80x20+275+420
40 EOT
41
42         print "$cmd\n" ;
43
44         chdir $tail_dir unless $cmd =~ /run_stem/ ;
45
46         fork_exec( $cmd ) ;
47
48         sleep 2 ;
49 }
50
51 1 while wait() != -1;
52
53 exit;
54
55
56
57 sub cleanup {
58
59         print "clean up\n" ;
60
61         kill 9, @children ;
62         wait ;  
63         exit ;
64
65 }
66
67 sub fork_exec {
68
69         my( $exec ) = @_ ;
70
71         if ( $pid = fork() ) {
72
73                 push @children, $pid ;
74                 return ;
75         }
76
77         exec $exec ;
78 }