N63050 第三周运维作业

五、文本处理工具和正则表达式
1、基本正则表达式(53分钟)
2、基本正则表达式和扩展正则表达式(50分钟)
3、文本处理三剑客之grep(43分钟)
4、shell脚本编程基础知识(14分钟)
5、shell脚本编程基础(48分钟)
6、shell脚本编程关于变量(62分钟)
7、shell脚本编程特殊变量和脚本安全(42分钟)
8、shell脚本编程算术运算(48分钟)
第六天
六、文本处理和shell编程基础
1、shell脚本编程逻辑运算和条件测试(55分钟)
2、shell脚本编程条件判断和条件组合(53分钟)
3、shell脚本编程条件判断If和case(52分钟)
4、shell脚本编程for循环(57分钟)
5、yum的私有仓库和内核升级(52分钟)
6、文件打包和压缩(48分钟)
6、文件打包和压缩(59分钟)
第三周
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来 注:grep nologin

复制代码
 1 [root@centos8 ~]#grep -v '/sbin/nologin' /etc/passwd | wc-l
 2 bash: wc-l: command not found...
 3 [root@centos8 ~]#grep -v '/sbin/nologin' /etc/passwd | wc -l
 4 9
 5 [root@centos8 ~]#grep -v '/sbin/nologin' /etc/passwd | cut -d: -f1
 6 root
 7 sync
 8 shutdown
 9 halt
10 brucelebron
11 mageia
12 user1
13 user2
14 user3
15 [root@centos8 ~]#
复制代码

 

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

1 [root@centos8 ~]#getent passwd | sort -t: -k3 -n |tail -1 | cut -d: -f1,3,7
2 nobody:65534:/sbin/nologin


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

1 [root@centos8 ~]#ss  -nt | grep -v '^State' | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]+ *$' |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' |sort | uniq -c
2       2 10.0.0.1
3       1 8.43.85.13

 

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

1
2
3
4
[root@centos8 ~]#cat disk.sh
df | tail -n +2 |tr -s ' ' |cut -d" " -f5 | tr -d % |sort -nr |head -1
[root@centos8 ~]#bash disk.sh
28

  

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

复制代码

#!/bin/bash
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|lscpu | grep -m1 'Model name' |tr ‘ ’ |cut -d: -f2`$END"
echo -e "MEMORY: $RED`free -h|grep Mem|tr -s ' ' : |cut -d : -f2`$END"
echo -e "DISK: $RED`lsblk |tr -s ' ' | cut -d " " -f4 |tail -n +3|head -n1`$END"
echo -e "$GREEN---------------------------------------------------------$END"

  

复制代码
复制代码
 1 [root@centos8 ~]#./systeminfo.sh 
 2 ----------------------Host systeminfo--------------------
 3 HOSTNAME:               centos8.mage.edu 
 4 IPADDR:                 10.0.0.150
 5 OSVERSION:              CentOS Linux release 8.5.2111
 6 KERNEL:                 4.18.0-348.7.1.el8_5.x86_64
 7 CPU:                    Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
 8 MEMORY:                 1.9Gi
 9 DISK:                   200G
10 ---------------------------------------------------------
复制代码

 


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

posted @   BruceLebron  阅读(34)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示