How to add a timestamp to bash script log?
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 printf ‘%s %s\n’ “$(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 … Read more