Wednesday, December 8, 2010

Maintain shell script log in CSV

Suppose you want to log the start and end of your shell script execution. Also you want to know the total execution time. Then you should do the followings -

  1. Put the start time in a variable at beginning of script;
    command - export start_date=`date +%m/%d/%Y,%H:%M:%S`.
    Be careful and use `` this operator to put the date function in a variable. Use the proper date format string as you need.

  2. Put the end in a variable at the end of script;
    command - export end_date=`date +%m/%d/%Y,%H:%M:%S`.

  3. Write the log and separate the field using ','.
    echo 'start,' $start_date ',end,' $end_date >> scriptexlog.csv


This is so simple!!

No comments: