日志传输与清除脚本

it2022-05-05  103

日志传输与清除脚本

transferlog.sh

#!/bin/bash # this script is execute at 18:00 hosts=(192.168.48.111 192.168.48.112) ssh_port='29922' log_path='/var/log/nginx' dst_path='/opt/log' today=$(date -d now +'%Y%m%d') for host in ${hosts[@]} do [ ! -d $dst_path/$host ] && mkdir -p $dst_path/$host scp -P $ssh_port root@$host:$log_path/access.log-$today.gz $dst_path/$host [ $? -eq 0 ] && echo "$today: transfer ok." >> $dst_path/$host.log || echo "$today: transfer error." >> $dst_path/$host.log done exit 0

cleanlog.sh

#!/bin/bash # this script is execute at 17:00 log_path='/opt/log' days='180' find $log_path -name 'access.log-*gz' -ctime +$days |xargs rm -rf exit 0 posted on 2015-05-15 12:39 北京涛子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liujitao79/p/4505642.html


最新回复(0)