美文网首页
第八周技术作业

第八周技术作业

作者: 神牧 | 来源:发表于2020-08-10 22:14 被阅读0次

    1、显示统计占用系统内存最多的进程,并排序。

    使用top命令显示系统资源使用情况,按M依照内存使用情况排序。

    image.png

    2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"

    for循环

    [root@localhost scripts]# vim for_ping.sh
    for i in {1..254};do
         {
          if  ping -W1 -c1 $NETID$i &> /dev/null;then
           echo ping:$NETID$i successs!
          else
           echo ping:$NETID$i fail
          fi
          }
    done
    wait
    [root@localhost scripts]# bash -n for_ping.sh 
    [root@localhost scripts]# chmod +x for_ping.sh 
    [root@localhost scripts]# ./for_ping.sh 
    ping:192.168.0.1 fail
    ping:192.168.0.2 fail
    ping:192.168.0.3 fail
    ping:192.168.0.4 fail
    ping:192.168.0.5 fail
    ping:192.168.0.6 fail
    ping:192.168.0.7 fail
    ping:192.168.0.8 fail
    ping:192.168.0.9 fail
    ping:192.168.0.10 fail
    ping:192.168.0.11 fail
    ping:192.168.0.12 fail
    ping:192.168.0.13 fail
    ping:192.168.0.14 fail
    ping:192.168.0.15 fail
    ping:192.168.0.16 fail
    ping:192.168.0.17 fail
    ping:192.168.0.18 fail
    ping:192.168.0.19 fail
    ping:192.168.0.20 fail
    ······  //以下输出省略
    

    while循环

    [root@localhost scripts]# vim while_ping.sh
    NETID=192.168.0
    i=1
    while [ $i -lt  255 ];do
         {
          if ping  -W1 -c1 $NETID.$i &> /dev/null;then
             echo ping:$NETID.$i success!
          else
             echo ping:$NETID.$i fail
          fi
         }
    done
    wait
    [root@localhost scripts]# bash -n while_ping.sh 
    [root@localhost scripts]# chmod +x while_ping.sh
    [root@localhost scripts]# ./while_ping.sh 
    ping:192.168.0.1 fail
    ping:192.168.0.2 fail
    ping:192.168.0.3 fail
    ping:192.168.0.4 fail
    ping:192.168.0.5 fail
    ping:192.168.0.6 fail
    ping:192.168.0.7 fail
    ping:192.168.0.8 fail
    ping:192.168.0.9 fail
    ping:192.168.0.10 fail
    ping:192.168.0.11 fail
    ping:192.168.0.12 fail
    ping:192.168.0.13 fail
    ping:192.168.0.14 fail
    ping:192.168.0.15 fail
    ping:192.168.0.16 fail
    ping:192.168.0.17 fail
    ping:192.168.0.18 fail
    ······  //以下输出省略
    

    3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间

    [root@localhost scripts]# vim bakup.sh
    BACKNAME=etcbak-`date -d -1day +%F-%H`
    tar -Jcvf /backup/${BACKNAME}.tar.xz /etc &> /dev/null
    [root@localhost scripts]# bash -n bakup.sh 
    [root@localhost scripts]# chmod +x bakup.sh 
    [root@localhost scripts]# crontab -e
    30 13 * * 1-5 /usr/bin/bash /data/scripts/bakup.sh
    [root@localhost scripts]# ./bakup.sh 
    
    [root@localhost scripts]# 
    [root@localhost scripts]# echo $?
    0
    [root@localhost scripts]# ll /backup/
    total 7640
    -rw-r--r--. 1 root root 7822328 Aug 10 21:28 etcbak-2020-08-09-21.tar.xz
    

    4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警

    [root@localhost scripts]# vim checkdisk.sh
    USED=`df -h|awk -F " +|%" '/^\/dev\/sd.*/{print $5}'|sort -nr|head -1`
    if [ $USED -gt 80 ];then
    mail root << eof
    someone disk used more than 80%,please check!
    eof
    fi
    [root@localhost scripts]# bash -n checkdisk.sh 
    [root@localhost scripts]# chmod +x checkdisk.sh 
    [root@localhost scripts]# crontab -e 
    30 13 * * 1-5 /usr/bin/bash /data/scripts/bakup.sh
    */10 * * * 1-5  /usr/bin/bash /data/scripts/diskcheck.sh
    
    

    相关文章

      网友评论

          本文标题:第八周技术作业

          本文链接:https://www.haomeiwen.com/subject/whysdktx.html