0

I use tee to capture output of an install script to a file in the usual way. All is fine except when there lxc-attach commands executing in an LXC Linux container. For example (see attached screenshot) on the right screen is the console output when using tee of the "lxc-attach -n container -- yum -y install" commands and on the left screen is the "tail -f log" of the tee'd log. As can see the tee log gets correct formatting, but when using tee the console output of the commands executing via lxc-attach get extra line breaks or tabs etc. Any way to use tee or a tee equivalent so that both the tee log and the console log are both formatted correctly? see screenshot

0

All the logged activity I need to capture is sudo commands. In case it helps anyone, here is the alternative solution I found here and here and am now using (I wrote the below code myself based on what I learned about this logging facility for sudo). It's very easy to use and provides highly-detailed logging. It is an amazing solution very happy with it and with sudoreplay you actually get "souvenir home videos" of you installs you can share with your grandchildren at Christmastime...

And, when the install session is over, you can optionally just deinstall the file in /etc/sudoers.d if you prefer.

I should add that this method has NONE of the problems that tee had when logging output from commands inside the LXC containers such as "lxc-attach" etc - of course it wouldn't.

Enjoy!

if [ ! -d "$DistDir"/installs/logs ]
then
    sudo mkdir -p "$DistDir"/installs/logs
fi

if [ -f "$DistDir"/installs/logs/$USER.log ]
then
    sudo mv "$DistDir"/installs/logs/$USER.log "$DistDir"/installs/logs/$USER.log.$LOGEXT
fi

if [ ! -d /var/log/sudo-io ]
then
    sudo mkdir -m 750 /var/log/sudo-io
fi

if [ ! -f /etc/sudoers.d/orabuntu-lxc ]
then
    sudo sh -c "echo 'Defaults      logfile=\"/home/$USER/Downloads/orabuntu-lxc-master/installs/logs/$USER.log\"'  >> /etc/sudoers.d/orabuntu-lxc"
    sudo sh -c "echo 'Defaults      log_input,log_output'                               >> /etc/sudoers.d/orabuntu-lxc"
    sudo sh -c "echo 'Defaults      iolog_dir=/var/log/sudo-io/%{user}'                     >> /etc/sudoers.d/orabuntu-lxc"
    sudo chmod 0440 /etc/sudoers.d/orabuntu-lxc
fi

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.