其中/var/log/ha/ha.log该文件是被复制文件,var/log/ha/log/$currentTimeStamp时间戳生成的文件复制的文件,/var/log/ha/cp_info.log是实行本shell的操作记录,同时本currentTimeStamp时间戳是长整型的
#!/bin/bash
#当前时间 <span style="font-family: Arial, Helvetica, sans-serif;">对应的毫秒时间戳</span>
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #将current转换为时间戳,精确到毫秒
if [ ! -d "/var/log/ha/log/" ];then
mkdir -p /var/log/ha/log #-p为父类不存在则生成,存在不影响
fi
if test -s /var/log/ha/ha.log; then #是否为 空或存在
echo "is not empty $currentTimeStamp" >/var/log/ha/cp_info.log
cp /var/log/ha/ha.log "/var/log/ha/log/"$currentTimeStamp
echo -n "" > /var/log/ha/ha.log # -n为指定为全空,不留第一行
else
echo "empty or not exist $currentTimeStamp" >/var/log/ha/cp_info.log
fi