log for script

You can pipe the script's output through a loop that prefixes the current date and time:
./script.sh | while IFS= read -r line; do echo "$(date) $line"; done >>/var/log/logfile
If you'll be using this a lot, it's easy to make a bash function to handle the loop:
adddate() {
    while IFS= read -r line; do
        echo "$(date) $line"
    done
}

./thisscript.sh | adddate >>/var/log/logfile
./thatscript.sh | adddate >>/var/log/logfile
./theotherscript.sh | adddate >>/var/log/logfile

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all