第四次作业

1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

grep -ic "/sbin/nologin" /etc/passwd
grep -i "/sbin/nologin" /etc/passwd | cut -f 1 -d ":"

2、查出用户UID最大值的用户名、UID及shell类型

getent passwd | sort -t ":" -rnk3 | head -n1


3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

netstat -nut | tr -s " " : | tail -n $(echo `netstat -unt | wc -l`-2|bc) | cut -f 4 -d ":" | sort | uniq -c

4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值

  1 #!/bin/bash
  2 #
  3 #************************************************************************************
  4 #Author:                Owen
  6 #Date:                  2021-01-10
  7 #FileName:              disk.sh
  9 #Descrition:            The test script
 10 #Copyright (C):     2021 All rights reserved
 11 #************************************************************************************
 12 echo "current highest disk usage:"
 13 df | grep '^/dev/sd' | grep -o ' *[0-9]\{1,3\}%' | sort -nr | head -n1

执行结果

current highest disk usage:
  22%

5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小

 1 #!/bin/bash
  2 #
  1 #!/bin/bash
  2 #
  3 #************************************************************************************
  4 #Author:                Owen
  6 #Date:                  2021-01-10
  7 #FileName:              disk.sh
  9 #Descrition:            The test script
 10 #Copyright (C):     2021 All rights reserved
 11 #************************************************************************************
 12 RED="\E[1;31m"
 13 GREEN="echo -e \E[1;32m"
 14 END="\E[0m"
 15 $GREEN---------------------------Host systeminfo-------------------------$END
 16 echo -e "HOSTNAME:          $RED`hostname`$END"
 17 echo -e "IPADDR:            $RED`ifconfig eth0 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n1 ` $END"
 18 echo -e "OS VERSION:            $RED `cat /etc/redhat-release` $END"
 19 echo -e "KERNEL:            $RED `uname -r`$END"
 20 echo -e "CPU:           $RED`lscpu | grep 'Model name' | tr -s ' ' | cut -d : -f 2`$END "
 21 echo -e "MEMORY:            $RED`free -h | grep Mem| tr -s ' ' : | cut -d : -f 2`$END "
 22 echo -e "DISK:          $RED`lsblk | grep '^sd' | tr -s ' ' | cut -d " " -f4`$END "
 23 $GREEN-------------------------------------------------------------------$END
posted @ 2021-01-12 09:21  无名小卒戊  阅读(82)  评论(1)    收藏  举报