第五次作业

 

第一题

[root@student scripts]# vim 21.sh     

#!/bin/bash

echo 1:gzip                                         

echo 2:bzip

echo 3:xz

[ -d /backups ] || mkdir /backups        

read -p "请输入序号指定打包压缩类型:" NAME   

case "$NAME" in

    1)

      tar -Pczvf /backups/etc-20160613.tar.gz /etc/* &>/dev/null

      ;;

    2)

      tar -Pcjvf /backups/etc-20160613.tar.bz2 /etc/* &>/dev/null

      ;;

    3)

       tar -PcJvf /backups/etc-20160613.tar.xz /etc/* &>/dev/null

 

       ;;

     [^0-3])

       echo "错误" 

       ;;

esac

 

#运行测试脚本

 

[root@student scripts]# bash 21.sh

1:gzip

2:bzip

3:xz

请输入序号指定打包压缩类型:5

选择错误

 

[root@student scripts]# ll /backups   

ls: cannot access '/backups': No such file or directory

[root@student scripts]# bash 21.sh 

1:gzip

2:bzip

3:xz

请输入序号指定打包压缩类型:1

[root@student scripts]# ll /backups         

total 7552

-rw-r--r--. 1 root root 7732782 Sep 21 09:43 etc-20160613.tar.gz

 

第二题

#编辑脚本,因为我根内存使用很少,我将条件改为大于20%时发邮件

[root@localhost ~]# vim /progress/03.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 -lt 20 ];then

        echo 内存报警 | mail -s "报警" -a /a.txt 18200560891@163.com < /a.txt

fi

#编辑例行性任务,每5分钟执行一次

[root@localhost ~]# crontab -e

*/5 * * * * bash /progress/03.sh

#查看crontab正在运行任务

[root@localhost ~]# crontab -l

*/5 * * * * bash /progress/03.sh

 

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值