一、
#编辑脚本
[root@www ~]# vi /script/bandzip.sh
#!/bin/bash
#获取参数
if [ "$arg1" = "gzip" ]; then
#使用tar和gzip归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.gz
tar -zcvf /backups/etc-20160613.tar.gz /etc
elif [ "$arg1" = "bzip2" ]; then
#使用tar和bzip2归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.bz2
tar -jcvf /backups/etc-20160613.tar.bz2 /etc
elif [ "$arg1" = "xz" ]; then
#使用tar和xz归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.xz
tar -Jcvf /backups/etc-20160613.tar.xz /etc
else
#显示错误压缩工具,并执行非正常退出
echo "错误压缩工具"
exit 1
fi
二、
#编辑脚本
[root@www ~]# vim /script/text.sh
#!/bin/bash
#根剩余内存
mem=`df | grep /dev/mapper/openeuler-root | tr -s " " " " | cut -d " " -f 4`
#根总共内存
total=`df | grep /dev/mapper/openeuler-root | tr -s " " " " | cut -d " " -f 2`
num=` echo $mem*100 / $total | bc`
if [ $num -ge 20 ]; then
echo 内存报警 | mail -s "报警" -a /a.txt sss3_z@163.com < /a.txt
fi
#编辑例行性任务,每5分钟执行一次
[root@www ~]# crontab -e
*/5 * * * * bash /script/text.sh