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