alager has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl $|=1; %hosts=( "host1" => "192.168.168.32", "host2" => "192.168.168.33", "host3" => "192.168.168.34" ); $file = "/var/log/bluebolt/bluebolt.log"; $tail = "/usr/bin/tail"; $ssh = "/usr/bin/ssh"; $grep = "/bin/grep --color=always"; #die "Usage: $0 <file>\n" unless @ARGV; if ($ARGV[0] eq "--help"){ print "Usage $0 [pattern]\n"; print "$0 will show all log files for App servers\n"; print "$0 [pattern] will grep the log files for the pattern\n" +; exit; } $SIG{CHLD} = 'IGNORE'; $SIG{INT} = sub {done("Received SIGINT")}; sub done { print "@_\n"; exit; } foreach $key (keys %hosts) { if(fork){ #parent process does nothing } else { #child process does all the work #add any grep commands here if ($ARGV[0]) { if ($ARGV[1]) { $command = "$ssh $hosts{$key} $tail - +f $file | $grep $ARGV[0] $ARGV[1]"; }else{ $command = "$ssh $hosts{$key} $tail - +f $file | $grep $ARGV[0]"; } } else { $command = "$ssh $hosts{$key} $tail -f $file"; } open (README, "$command |") or die "Couldn't fork: $!\ +n"; select README; $|=1; while(<README>){ print STDOUT "$hosts{$key}: "; print STDOUT $_; } } } while(1){sleep(5);}#parent process needs to wait for Ctrl-C exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: why the long delays?
by ikegami (Patriarch) on Apr 15, 2010 at 17:23 UTC | |
by alager (Acolyte) on Apr 15, 2010 at 18:26 UTC | |
|
Re: why the long delays?
by MidLifeXis (Monsignor) on Apr 15, 2010 at 17:22 UTC |