ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 第四周

第四周

原创 Linux操作系统 作者:1经天纬地1 时间:2021-04-04 19:44:43 0 删除 编辑

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

[root@CentOS8 ~]#grep -v '/sbin/nologin' /etc/passwd |cat -b
     1	root:x:0:0:root:/root:/bin/bash
     2	sync:x:5:0:sync:/sbin:/bin/sync
     3	shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
     4	halt:x:7:0:halt:/sbin:/sbin/halt


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

[root@CentOS8 ~]#cat /etc/passwd |sort -nrt: -k3 |cut -d: -f1,3,7 |head -n1
nobody:65534:/sbin/nologin


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

[root@CentOS8 ~]#ss -nt |tail -n+2 |tr -s ' ' : |cut -d: -f 6 |sort |uniq -c |sort -nr
     14 10.0.0.205
      3 10.0.0.202
      1 10.0.0.204
      1 10.0.0.1


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

[root@CentOS8 ~]#cat dish.sh 
#!/bin/bash
#
#***************************************************************
#Date:                2021-04-04
#FileName:            dish.sh
#Description:         The test script
#Copyright (C):       2021 All rights reserved
#***************************************************************
df | tail -n+2 |tr -s ' ' % |cut -d% -f5 |sort -nr |head -1
[root@CentOS8 ~]#bash dish.sh 
14


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

[root@CentOS8 ~]#cat systeminfo.sh 
#!/bin/bash
#
#***************************************************************
#Date:                2021-04-04
#FileName:            systeminfo.sh
#Description:         The test script
#Copyright (C):       2021 All rights reserved
#***************************************************************
RED="\E[1;31m"
GREEN="\E[1;32m"
END="\E[0m"
echo -e "$GREEN----------------------Host systeminfo--------------------$END"
echo -e "HOSTNAME: $RED`hostname`$END"
echo -e "IPADDR: $RED` ifconfig ens33|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' |head -n1`$END"
echo -e "OSVERSION: $RED`cat /etc/redhat-release`$END"
echo -e "KERNEL: $RED`uname -r`$END"
echo -e "CPU: $RED`lscpu|grep 'Model name'|tr -s ' '|cut -d : -f2`$END"
echo -e "MEMORY: $RED`free -h|grep Mem|tr -s ' ' : |cut -d : -f2`$END"
echo -e "DISK: $RED`lsblk |grep '^sd' |tr -s ' ' |cut -d " " -f4`$END"
echo -e "$GREEN---------------------------------------------------------$END"
[root@CentOS8 ~]#bash systeminfo.sh 
----------------------Host systeminfo--------------------
HOSTNAME: CentOS8
IPADDR: 10.0.0.205
OSVERSION: CentOS Linux release 8.1.1911 (Core) 
KERNEL: 4.18.0-147.el8.x86_64
CPU:  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
MEMORY: 1.9Gi
DISK: 200G
---------------------------------------------------------

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69965557/viewspace-2765579/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 第二周
下一篇: 第五周
请登录后发表评论 登录
全部评论

注册时间:2020-03-05

  • 博文量
    12
  • 访问量
    16130