第四周作业

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

[root@localhost ~]# getent passwd| grep ".*/sbin/nologin$"  | cut -d : -f1;echo "total is `getent passwd| grep ".*/sbin/nologin$"  | cut -d : -f1  |wc -l` "
bin
daemon
adm
lp
mail
operator
games
ftp
nobody
dbus
systemd-coredump
systemd-resolve
tss
polkitd
unbound
sssd
sshd
total is 17 

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

[root@route1 ~]# getent passwd | cut -d : -f3,1,7 | sort -k 2 -t : -n | tail -1
user3:2005:/bin/bash

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

[root@route1 ~]#  ss -nt | tr -s " " | cut -d " " -f5 | cut -d":" -f1 | tail -n+2 | sort | uniq -c 
      2 192.168.179.1
      1 192.168.179.153
[root@route1 ~]# 

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

[root@route1 script]# bash disk.sh 
this system The maximum utilization is 24%
[root@route1 script]# cat disk.sh 
#!/bin/bash
p=`df -h | grep "^/dev/sd" | tr -s " " | cut -d " " -f5 | sort -nr | head -1`
echo "this system The maximum utilization is $p"

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

[root@route1 script]# bash information.sh 
---------------------------------HOSTINFORMASTION-----------------------------------------
HOSTNAME:         route1
IPADDR:           127.0.0.1 172.18.0.200 172.18.255.255 192.168.179.131 192.168.179.255 172.16.0.200 172.16.255.255 192.168.179.100 192.168.179.255 
CPU:              Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 
MEMORY:           3.7G
DISK:             30G 50G 10G 10G 
SYSTEM_VERSION:   CentOS Linux release 7.4.1708 (Core)  
KERNEL_VERSION:   3.10.0-693.el7.x86_64 
----------------------------------------------------------------------------------------
[root@route1 script]# 
[root@route1 script]# cat information.sh 
#!/bin/bash
EEN2="echo -e \E[1;32m"
RED="\E[1;31m"
GREEN="\E[1;32m"
YELLOW="\E[1;33m"
END1="\E[0m"
echo -e "$RED---------------------------------HOSTINFORMASTION-----------------------------------------$END1"
echo -e "HOSTNAME:     $GREEN    `hostname`$END1"
echo -e "IPADDR:       $GREEN    `ip add list  | egrep -o "\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>(\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>){2}\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>" | tr '\n' ' ' `$END1"
echo -e "CPU:          $GREEN   `lscpu | grep "Model name" | tr -s ' '| cut -d: -f2 | tr '\n' ' '`$END1"
echo -e "MEMORY:       $GREEN    `free -h | grep Mem | tr -s ' ' '%' | cut -d'%' -f2`$END1"
echo -e "DISK:         $GREEN    `lsblk | grep "^sd" |tr -s ' ' | cut -d' ' -f4 | tr '\n' ' '`$END1"
echo -e "SYSTEM_VERSION:$GREEN   `cat  /etc/redhat-release` $END1"
echo -e "KERNEL_VERSION:$GREEN   `uname -r` $END1"
echo -e "$GREEN----------------------------------------------------------------------------------------$END1"
[root@route1 script]# 

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

posted @ 2021-03-08 00:03  recvfrom  阅读(77)  评论(0)    收藏  举报