日志集中传输脚本
log srv
#!/bin/bash
# crontab
# */15 5 * * * root /bin/sh /opt/pull_log.sh >/dev/null 2>&1
#!/bin/bash
today=$(date -d now +%Y%m%d)
old=$(date -d '90 days ago' +%Y%m%d)
log_path='/opt/log'
for i in 10.160.1.211 10.160.1.212 10.160.1.213
do
{
# download new log
[ ! -d $log_path/$i ] && mkdir -p $log_path/$i
pid=$(ps aux|grep $i |grep wget|awk '{print $2}')
if [ -n $pid ]; then
kill -9 $pid
fi
#curl -C - http://$i/access.log-$today.gz -o $log_path/$i/access.log-$today.gz
wget -c http://$i/access.log-$today.gz -O $log_path/$i/access.log-$today.gz
# delete old log
[ -d $log_path/$i/access.log-$old.gz ] && rm -rf $log_path/$i/access.log-$old.gz
} &
done
exit 0
web srv
#!/bin/bash
# crontab
# 30 4 * * * root /bin/sh /opt/link_log.sh create >/dev/null 2>&1
# 30 5 * * * root /bin/sh /opt/link_log.sh delete >/dev/null 2>&1
today=$(date -d now +%Y%m%d)
if [ $1 == 'create' ]; then
ln -s /var/log/nginx/access.log-$today.gz /opt/www/access.log-$today.gz
fi
if [ $1 == 'delete' ]; then
[ -L /opt/www/access.log-$today.gz ] && rm -rf /opt/www/access.log-$today.gz
fi
exit 0
posted on
2016-07-21 15:51
北京涛子 阅读(
...) 评论(
)
编辑
收藏
转载于:https://www.cnblogs.com/liujitao79/p/5692082.html