第三周作业

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

[root@Centos8 ~]# grep -v '/sbin/nologin' /etc/passwd|cut -d: -f1
root
sync
shutdown
halt
dt

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

[root@Centos8 ~]# cat /etc/passwd | cut -d: -f1,3,7 | sort -t: -k2 -n |tail -n1
nobody:65534:/sbin/nologin

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

[root@Centos8 ~]# netstat -antpl|grep ESTABLISHED|awk '{print $5}'|awk -F : '{print $1}'|grep -v 127.0.0.1 |sort -n |uniq -c |sort -nr
3 10.0.0.1
1 10.0.0.169
1 10.0.0.159
1 10.0.0.151

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

[root@Centos8 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 947M 0 947M 0% /dev
tmpfs 976M 0 976M 0% /dev/shm
tmpfs 976M 9.4M 967M 1% /run
tmpfs 976M 0 976M 0% /sys/fs/cgroup
/dev/sda1 100G 5.3G 95G 6% /
/dev/sda2 50G 390M 50G 1% /data
/dev/sda5 976M 186M 723M 21% /boot
tmpfs 196M 1.2M 194M 1% /run/user/42
tmpfs 196M 0 196M 0% /run/user/0
[root@Centos8 ~]# df -h|awk '{print $1,$5}' |grep -v Filesystem |sort -k 2 -nr|head -1
/dev/sda5 21%

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

[root@Centos8 ~]# vim systeminfo.sh

echo -e "My hostname is `hostname`"
echo -e "IP address is `ifconfig ens33 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`"
echo -e "OS version is `cat /etc/redhat-release`"
echo -e "Kernel version is `uname -r`"
echo -e "CPU type is` lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`"
echo -e "Memtotal is `cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`"
echo -e "Disk space is `lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`"

[root@Centos8 ~]# bash systeminfo.sh
My hostname is Centos8.4-1.mgedu.org
IP address is 10.0.0.156
OS version is CentOS Linux release 8.4.2105
Kernel version is 4.18.0-305.3.1.el8.x86_64
CPU type is AMD Ryzen 7 5800H with Radeon Graphics
AMD Ryzen 7 5800H with Radeon Graphics
Memtotal is 1997772 kB
Disk space is 200G

六、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)

posted @ 2021-11-03 12:02  习得  阅读(41)  评论(0)    收藏  举报