Re: Filtering socklog output revisited
Alex Efros <[email protected]>
| Newsgroups | gmane.comp.misc.pape.general |
|---|---|
| Organization | asdfGroup Inc., http://powerman.asdfGroup.com/ |
| Message-ID | <[email protected]> |
Hi! On Tue, Aug 29, 2006 at 09:28:14PM -0400, George Georgalis wrote: > Why not... Reread my previous message. At first - exec with pipe doesn't work, look at this example: --- exec.sh --- #!/bin/bash exec sed s/a/b/ | cat --- Look at `ps axf` while script is running and you'll see exec not working: --- ps --- 30025 ? S 0:00 \_ xterm -name 6sh 17480 pts/9 Ss 0:00 | \_ -bash 3062 pts/9 S+ 0:00 | \_ /bin/bash tmp/exec.sh 20574 pts/9 S+ 0:00 | \_ sed s/a/b/ 19739 pts/9 S+ 0:00 | \_ cat --- To have exec working in this case I've developed script 'execpipe', you can look at it if interested (in attach). Licence is 'Free'. :) > exec chpst -ulog sed -e 's/y.y.y.y/x.x.x.x/g' | svlogd \ At second - if svlogd die it will not be restarted. -- WBR, Alex.
execpipe
(text/plain, 962 B)
#!/usr/bin/perl
use version; our $VERSION = qv('0.0.2');
use warnings;
use strict;
main(@ARGV) unless caller();
sub err { die "Unable to exec: <$_[0]>\n" }
sub execpipe {
my ($cmd1, $cmd2) = @_;
open(STDOUT, '|-', @$cmd2) or err("@$cmd2");
exec(@$cmd1), err("@$cmd1");
}
sub execpipe2 {
my ($cmd1, $cmd2) = @_;
open(STDIN, '-|', @$cmd1) or err("@$cmd1");
exec(@$cmd2), err("@$cmd2");
}
sub main {
if (@ARGV == 2) {
execpipe([$ARGV[0]], [$ARGV[1]]);
}
elsif (@ARGV == 3 && $ARGV[0] eq '-2') {
execpipe2([$ARGV[1]], [$ARGV[2]]);
}
print <<"EOUSAGE";
execpipe $VERSION, (c) Alex Efros 2006
Usage: $0 [-2] "first command" "second command"
Equivalent to bash script:
first command | second command
but without leaving bash in memory until these commands exits.
Will exit when "first command" exit.
If option -2 given, exit when "second command" exit.
EOUSAGE
}