Rajeev Kannav Sharma

Posts About

unix linux shell script code snippet

11 Jul 2015

Generating script logs with timestamp

Just as the duration of script it’s useful to have time-stampped log. Use following function to log time for every output.

  log() {
       echo [`date +%Y-%m-%d\ %H:%M:%S`] $*

Call the function as follows instead of simply “echo”ing.

  log "my string to be logged"
Reading variables from config file

Create a config file with contents as follows:


Add following line in the beginning of the shell script:

. configfile

This will load the key value pairs and you may verify & access the values as $key1 or $key2.

And if you get stuck… Ask Here

email me rajeevsharma86@gmail.com

Tweet to me at @rajeevkannav.