第三周作业

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

[15:17:49 root@centos7 ~]#getent passwd | grep -v "/sbin/nologin" | cut -d: -f1
root
sync
shutdown
halt
amandabackup
alex
mage
wang
rooter

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

[13:53:36 root@centos7 ~]#getent passwd|sort -n -t: -k3|cut -d: -f1,3,7|tail -1
nfsnobody:65534:/sbin/nologin

3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[14:54:12 root@centos7 ~]#netstat -nt | tr -s ' ' : | cut -d : -f6 |sort -nr |uniq -c |head -n2

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

[15:09:44 root@centos7 ~]#cat disk.sh 
#!/bin/bash
df -h | tail  -n +2 |tr -s " "  | cut -d " " -f5 |sort -rn |head -1

[15:14:52 root@centos7 ~]#df | grep /dev/sda1 | grep -Eo '[0-9]+%'
17%

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

20:09:15 root@Centos8 date]#cat system_info.sh 
#!/bin/bash
##############################################################
# File Name: system_info.sh
# Version: V1.0
# Author: magedu
# Organization: www.magedu.com
# Created Time : 2022-10-26 20:01:44
# Description:
##############################################################
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 ens160|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|head -1`$END"
echo -e  "MEMORY:       $RED`free -h|grep Mem|tr -s ' ' : |cut -d : -f2`$END"
echo -e  "DISK:         $RED`lsblk |grep '^nv' |tr -s ' ' |cut -d " " -f4`$END"
echo -e  "$GREEN---------------------------------------------------------$END"

[20:10:08 root@Centos8 date]#bash system_info.sh 
 ----------------------Host systeminfo--------------------
 HOSTNAME:     Centos8.magedu.org
 IPADDR:       10.0.0.41
 OSVERSION:    CentOS Linux release 8.4.2105
 KERNEL:       4.18.0-305.3.1.el8.x86_64
 CPU:          12th Gen Intel(R) Core(TM) i7-12700K
 MEMORY:       942Mi
 DISK:         200G
 ---------------------------------------------------------
posted @   Alexander7  阅读(15)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示