將歷史記錄時間戳替換爲標準時間

#!/bin/sh
history_dir=/tmp/history/test/2012-11-20                #歷史日誌目錄
for file_name in $history_dir/*
do
        while read file
        do
         time=`echo $file | grep "#"`                                                    
         if [ $? -eq 0 ]                                                                        
         then
                new_time=`echo $time | sed 's/#//g'`
                date_time=`echo $new_time | awk '{print strftime ("%F %T",$0)}'`
                sed -i "s/$time/$date_time/g" $file_name
         fi
        done<$file_name
done
替換前日誌格式以下:
  #1353398866
  ls /root/
  #1353398881
  history -w
替換後日志格式以下:
  2012-11-20 16:07:46
  ls /root/
  2012-11-20 16:08:01
  history -w
相關文章
相關標籤/搜索