1.
[root@master ~]# vi /script/zy1.sh
#!/bin/bash
# 获取参数
if [ "$1" = "gzip" ]; then
# 使用tar和gzip归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.gz
tar -zcvf /backups/etc-20160613.tar.gz /etc
elif [ "$1" = "bzip2" ]; then
# 使用tar和bzip2归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.bz2
tar -jcvf /backups/etc-20160613.tar.bz2 /etc
elif [ "$1" = "xz" ]; then
# 使用tar和xz归档压缩/etc目录至/backups目录中,并命名为/backups/etc-20160613.tar.xz
tar -Jcvf /backups/etc-20160613.tar.xz /etc
else
# 显示错误压缩工具,并执行非正常退出
echo "错误压缩工具"
exit 1
fi
2.
[root@master~]# vi /script/zy2.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 "警告" Donc_97@163.com
fi
[root@master ~]# crontab -e
*/5 * * * * bash /script/zy2.sh