第四周
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos8 ~]$grep -vE 'sbin/nologin$' /etc/passwd |wc -l
12
[root@centos8 ~]$grep -vE 'sbin/nologin$' /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
wang:x:1000:1000:wang:/home/wang:/bin/bash
gentoo:x:1001:1001:Gentoo Distribution:/home/gentoo:/bin/csh
nginx:x:1002:1003::/home/nginx:/bin/bash
varnish:x:1003:1004::/home/varnish:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
user1:x:2003:2003::/home/user1:/bin/bash
user2:x:2004:2004::/home/user2:/bin/bash
user3:x:2005:2005::/home/user3:/bin/bash
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos8 ~]$sort -t : -k 3 -n /etc/passwd|cut -d: -f 1,3,7|tail -n -1
nobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos8 ~]$ss -ntu|grep -e ^tcp -e ^udp|awk '{print $6}'|cut -d: -f1|sort -r|uniq -c
4 10.0.0.1
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@centos8 ~]$cat disk.sh
#!/bin/bash
df|grep ^\/dev|sort -nrk5|awk '{print "partition:"$6 "\tusage: " $5}'
[root@centos8 ~]$bash disk.sh
partition:/boot usage: 15%
partition:/ usage: 3%
partition:/data usage: 1%
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@centos8 data]$cat systeminfo.sh
#!/bin/bash
HOST=$(hostname)
IPV4=$(nmcli con show eth0|awk '/ipv4.addresses/{ print $2}')
OS=$(cat /etc/os-release |head -1|awk -F= '{ print $2 }')
KERNEL=$(uname -r)
CPU=$(lscpu|awk -F: '/^Model name/{ print $2}'|tr -s ' ')
MEM=$(lsmem |awk -F: '/Total online memory/{ print $2}'|tr -s ' ')
DISK=$(fdisk -l|awk -F',' '/Disk \/dev/ {print $1}')
echo "The Host infomation is: "
echo -e "主机名:\t\t $HOST"
echo -e "IPv4地址:\t $IPV4"
echo -e "操作系统版本:\t $OS"
echo -e "内核版本:\t $KERNEL"
echo -e "CPU型号:\t$CPU"
echo -e "内存大小:\t$MEM"
echo -e "硬盘大小:\t $DISK"
[root@centos8 data]$bash systeminfo.sh
The Host infomation is:
主机名: centos8.test.com
IPv4地址: 10.0.0.8/24
操作系统版本: "CentOS Linux"
内核版本: 4.18.0-147.el8.x86_64
CPU型号: Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
内存大小: 1G
硬盘大小: Disk /dev/sda: 200 GiB