bash - How can you redirect a script's output through a process? -
i want redirect bash script's output through logging program. specifically, apache's logrotate utility. redirection needs set within script itself.
if redirection done on command line, while executing script, this:
myscript | logrotate -l $logfile.%f 86400 2>&1
here pseudo-code goes inside script accomplish output redirection, not work:
exec >(logrotate -l $logfile.log.%f 86400) 2>&1
you can using named pipe.
pipe=/var/run/myscript/pipe mkfifo "$pipe" logrotate -l "$logfile.%f" 86400 < "$pipe" & exec > "$pipe"
also, regarding 2>&1 redirection -- make sure understand applied. in first example it's applied logrotate, while in second "example" applied script.
Comments
Post a Comment