#!/bin/bash
#################################################
#
#      Filename: monitor_coredump.sh
#
#        Author: scott.liu@ucloud.cn
#   Description: ---
#        Create: 2019-03-07 17:36:48
# Last Modified: 2019-04-03 11:46:30
#################################################
#监控/home/core目录下文件的modify日期在5分钟之内是否发生过变动
DIR="/home/core"

if [ ! -d $DIR ];then
    echo '[{"value":0,"tags":""}]'
    exit 0
fi
#获取5分钟前时间
now_time=`date "+%Y-%m-%d %H:%M" -d '-5 min' | awk -F- '{print $1 $2 $3}' | awk '{print $1$2}' | awk -F: '{print $1$2}'`

ret='[{"value":0,"tags":""}]'
for file in `ls -f $DIR | grep -Ev 'sas3ircu|sas2ircu'`; do
    filepath="$DIR/$file"
    if [ ! -e $filepath -o ! -f $filepath ]; then
        continue
    fi

    modify_time=`stat $filepath | grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}' | awk -F- '{print $1$2$3}' | awk -F: '{print $1$2}'`
    if [[ $now_time -gt $modify_time ]]; then
        continue
    else
        ret='[{"value":1,"tags":""}]'
        break
    fi
done

echo "$ret"
exit 0
