Option 1
#!/bin/bash
sudo apt install -y package_name | tee -a /tmp/app.log >/dev/null
sudo apt install -y package_name1 | tee -a /tmp/app.log >/dev/null
sudo apt install -y package_name2 | tee -a /tmp/app.log >/dev/null
Option 2
disable all output to tty but save to file
#!/bin/bash
exec 1> >(tee -a /tmp/app.log >/dev/null)
sudo apt install -y package_name
sudo apt install -y package_name1
sudo apt install -y package_name2
Option 3
enable all output to tty and save to file
#!/bin/bash
exec 2> >(tee -a /tmp/app.log >&2) > >(tee -a /tmp/app.log")
sudo apt install -y package_name
sudo apt install -y package_name1
sudo apt install -y package_name2
As function
function __application_log(){
if [ "${__verbose_mode}" == "no" ]; then
exec 1> >(tee -a /tmp/app.log >/dev/null)
else
exec 2> >(tee -a /tmp/app.log >&2) > >(tee -a /tmp/app.log")
fi
}
Top comments (0)