2025-01-02 10:46:09 +08:00

27 lines
652 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 读取每个IP地址
while read -r line; do
ip=$(echo $line | awk '{print $2}') # 获取IP地址
# 初始化总和为0
sum=0
# 处理每个日志文件
for log_file in /root/eo/*; do
# 计算这个IP地址在这个日志文件中对应的第六列的总和
sum_in_file=$(grep $ip $log_file | awk '{total += $6} END {print total}')
# 如果 sum_in_file 为空设置为0
if [ -z "$sum_in_file" ]; then
sum_in_file=0
fi
# 将这个总和加到总和中
sum=$(echo $sum + $sum_in_file | bc)
done
# 输出IP地址和对应的总和
echo "$ip $sum"
done < ip_list.txt > bytes.txt