I have written multi-os provisioning script for local and aws ec2 VMs.
I want to achieve this behaviour of the script:
stdout
and stderr
in terminal during executionprovision-full.log
stderr
to another file provision-err.log
Is that possible at all? I have googled a lot for the solution with no success. Am I miss something? I mean, maybe it's impossible to do by system design :)
The provision script has this design:
#!/bin/bash
# defining functions
{
# some script here
} |& tee ~/full-provision.log
The closest solutions that I have been able to achieve:
|& tee ~/full-provision.log
for local VMs, so I could see output in terminal and later I'm able to inspect full-provision.log
2> /var/log/provision-err.log > /var/log/provision-out.log
for aws ec2 VMs with 2 separate log files for inspection.Duplicate standard error by redirecting it to process substitution tee /var/log/provision-err.log
:
{ { # some script here } 2> >(tee /var/log/provision-err.log 1>&2); } |&
tee ~/full-provision.log
The only subtlety is that the standard output of the process substitution shall be redirected back to the standard error (1>&2
) if we want to preserve the separation between standard output and standard error. If you don't care the following shall work about the same:
{ { # some script here } 2> >(tee /var/log/provision-err.log); } |
tee ~/full-provision.log
Note that this works only if your OS supports named pipes.