日志归集脚本
作者:互联网
需求:收集系统日期前一天的日志,归集到统一目录下,并需要有模块名称和ip标识;
#!/bin/bash echo "===log backup start===" #判断执行用户,为hps用户 if [ $(whoami) != hps ] then echo "execute user must be [hps]!" exit 2 fi #注意月末最后一天日志会在下一个月目录下 ip=`ifconfig | grep inet | head -1 | awk '{print $2}'` month1=`date +'%Y%m'` day1=`date +'%Y%m'%d'` day2=`date -d "1 day ago" +'%Y%m'%d'` day3=`date -d yesterday +%F` backupDir=/tmp/$ip/$month1/$day2 mkdir -p $backupDir cd /home/hps/logs if [ -d /home/hps/logs/history ];then find /home/hps/logs/history -name "*log*" -type f | grep $day3 | xargs -I {} tar -czf {}.api.$ip.tar.gz find /home/hps/logs/history -name "*gz*" | grep $day3 | xargs -I {} mv {} $backupDir fi echo "===log backup end==="
标签:脚本,logs,hps,ip,Y%,归集,date,home,日志 来源: https://www.cnblogs.com/llwxhn/p/15415500.html