I am currently using following to log stdout and stderr. I want to log echo statements along with timestamp.
exec 3>&1 1>>${LOG_FILE} 2>&1
How can I achieve it using shell
Depending on the exact intended behavior you may want the ts
utility.
% echo message | ts
Apr 16 10:56:39 message
You could also alias echo
.
% sh
$ alias echo='echo $(date)'
$ echo message
Mon Apr 16 10:57:55 UTC 2018 message
Or make it a shell function.
#!/bin/sh
echo() {
command echo $(date) "$@"
}
echo message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With