Re: Shell script timestamp variable
What you can do is keep the format in a variable to make sure that the same date format is used consistently. But considering that all logging goes also to the same file, if you want to make your logging simpler you write a function:
Code:
function log {
printf "%s (%06d): %s\n" "$(date '+%F %H:%M:%S')" $$ "$*" >> /some/path/to/file.log
}
and in your code
Code:
log "this line will be logged"
log this line will be logged too
Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Bookmarks