我们需要审查执行脚本的日志,所以我们必须合理的配置日志,当然了,作为一般日志的约定,我们希望让日志放在一个指定目录下,并且日志文件的名字会有当天的时间命名:

 

 

 

首先,我们创建日志目录,如果不存在的话:

 
  
  1. #create the log directory if not exist 
  2. cd $MODIFICATION_ROOT 
  3. if [ ! -d "LOGGING_FOLDER_NAME" ]; 
  4.  then  
  5.     mkdir $LOGGING_FOLDER_NAME; 
  6.     echo "the logging root directory $LOGGING_ROOT is created" 
  7. fi 
  8.  
  9. #create the log directory of tarball shell if not exist 
  10. cd $LOGGING_ROOT 
  11. if [ ! -d "TARBALL_LOGGING_FOLDER_NAME" ]; 
  12.   then 
  13.     mkdir $TARBALL_LOGGING_FOLDER_NAME; 
  14.     echo "the tarball shell logging root directory $TARBALL_LOGGING_ROOT is created" 
  15. fi  

 

 

然后我们设置log文件的文件名,让其用date 作为文件名:

 
  
  1. #Set the tarball shell log file name 
  2. CURRENT_DATE=`date +%Y%m%d` 
  3. TODAYLOG="$TARBALL_LOGGING_ROOT/tarball_${CURRENT_DATE}.log" 
  4. echo $TODAYLOG 
  5. #if not exist this file ,then create a new one 
  6. if [ ! -f $TODAYLOG ]     
  7. then 
  8. cd $TARBALL_LOGGING_ROOT 
  9. touch $TODAYLOG 
  10. fi 
  11.   

 

最后我们设置日志的格式:

 
  
  1. #Set the logging format 
  2. LOG_TIME_FORMAT=`date +%Y-%m-%d-%r`