RHCE练习

一、

#编辑脚本
[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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值