需求: 从 hive-server2.log 中截取所有当天日志,并统计其时间的平均值和时长最长的时间 hive-server2.log 登录后复制 2024-05-01 12:00:00 INFO [HiveServer2] Starting query execution 2024-05-01 12:00:01 INFO [HiveServer2] Query executed successfully in 5 seconds 2024-05-01 12:00:08 INFO [HiveServer2] Query result returned to client 1.2.3. 实现: hive.sh 登录后复制 #!/bin/bash awk '{print $2}' hive-server2.log |tr -d ":" | awk '{sum+=$1} END {print "avg:",sum/NR}' >>/root/hive.output awk '{print $2}' hive-server2.log |tr -d ":" | awk '{max = 0} {if ($1+0 > max+0) max=$1} END {print "Max: ",max}' >>/root/hive.output 1.2.3.4.5. 验证: 登录后复制 [root@logstash ~]# sh hive.sh [root@logstash ~]# cat hive.output avg: 120003 Max: 120008 [root@logstash ~]# 1.2.3.4.5. 原创作者: ztj1216 转载于: https://blog.51cto.com/ztj1216/11286843