Thursday, September 6, 2012

Writing Bash Shell Logs With Date & Time

Bash shell scripts can be used to do a variety of things. It is very easy to schedule the script to run under crontab. It would be helpful if we log the steps with date time and a message. It can be done as follows.
echo '['`date +%F\ %T`'] Downloading file abc'
#outputs: [2012-09-06 23:20:16] Downloading file abc
NB: The date command is enclosed in back tick, not single quote.