#!/bin/bash
CD=`df -l |awk‘NR==3 {print $4}‘|awk ‘BEGIN {FIELDWIDTHS="2 1"}‘‘{print $1}‘`
if [ $CD -ge 20];then
echo "硬盘空间已满,不能进行备份"| mutt -s "备份报警,请及时更换硬盘" [email protected]&& exit 1
fi
logrotate -f/etc/logrotate.conf
tar zcf/opt/backup/`date +%Y%m%d%H%M`.tat.gz /var/log/messages.* &>/dev/null
RT=`echo $?`
if [ $RT -eq 0];then
echo "`date +%Y%m%d%H%M`备份成功" | mutt -s "备份成功" [email protected]
else
echo "`date +%Y%m%d%H%M`备份失败" | mutt -s "备份失败,请及时查看" [email protected]
fi
时间: 2024-10-07 22:49:13