More elegant implementation than this?
- From: gerg@xxxxxxxxx (Greg Andrews)
- Date: Sun, 4 Dec 2005 05:05:19 +0000 (UTC)
Under the bourne shell on Solaris 8 I have a shell script that starts
a java command with stdout and stderr redirected to a logfile and the
pid saved to another file. Like this:
$java_command >> $logdir/output.log 2>&1 &
echo $! > $logdir/command.pid
I need to switch to piping stdout and stderr to another program that
writes it to the logfile and rolls the logfile when it gets too large.
I tried the simple and obvious approach of just changing the redirection:
$java_command | $log_command $logdir/output.log &
echo $! > $logdir/command.pid
or
(exec 2>&1; exec $java_command) | $log_command $logdir/output.log &
echo $! > $logdir/command.pid
However the pid saves is the one from $log_command rather than from
$java_command.
After some more experimenting, I've come up with the following.
It works, but it seems a bit clunky. Have I overlooked a more
elegant way? (at the moment I can't change to a different shell)
sh -c "echo \$$ > $logdir/command.pid; exec 2>&1; exec $java_command" \
| $log_command $logdir/output.log &
Thanks,
-Greg
--
::::::::::::: Greg Andrews ::::: gerg@xxxxxxxxx :::::::::::::
I have a map of the United States that's actual size.
-- Steven Wright
.
- Follow-Ups:
- Re: More elegant implementation than this?
- From: Stachu 'Dozzie' K.
- Re: More elegant implementation than this?
- Prev by Date: Re: use of quotes in assignment of variable to variable
- Next by Date: Re: Ann: yruba --- rule evaluation for the shell
- Previous by thread: non interactively feeding a file to a command
- Next by thread: Re: More elegant implementation than this?
- Index(es):
Relevant Pages
|