#!/bin/bash
year=$(date +"%Y")
month=$(date +"%m")
day=$(date +"%d")
surf_path="/MDFS/DATA/XB/INCOME/STATION/SURF/${year}/${year}${month}/${year}${month}${day}"
host_name=$(hostname)
# 使用find命令查找匹配的文件,并通过while循环遍历每个文件
if [ -d "$surf_path" ]; then
find "$surf_path" -name "*.csv" | while read file; do
# 使用stat命令获取每个文件的filestat信息,并输出
file_size=$(stat -c "%s" "$file")
file_create_time=$(stat -c "%Y" "$file")
file_name=$(basename "$file")
timestamp="";
if [[ $file_name =~ [0-9]{10} ]]; then
time_part="${BASH_REMATCH[0]}"
timestamp=$(date -d "${time_part:0:4}-${time_part:4:2}-${time_part:6:2} ${time_part:8:2}:00:00" +%s)
else
timestamp=""
fi
current_time=$(date +%s%N)
echo "filestat,file=$file_name,host=$host_name exists=1i,size=${file_size}i,obs_time=${timestamp},modification_time=${file_create_time}i $current_time"
done
fi
telegraf数据源监控
最新推荐文章于 2024-07-31 18:38:45 发布