shell编程练习(三): 笔试21-30
笔试练习(三):
21、编写shell程序,实现自动删除30个账号的功能。
账号名为std01至std30。
[root@VM_0_5_centos test]# vi 21.sh
[root@VM_0_5_centos test]# cat 21.sh
#!/bin/bash
#编写shell程序,实现自动删除30个账号的功能。账号名为std01至stud30
#要有root权限 for i in {9901..9930}; do
xx=`echo $i | sed 's/99//g'`
userdel -r std$xx
done
22、用户清理,清除本机除了当前登陆用户以外的所有用户
[root@VM_0_5_centos test]# vi 22.sh
[root@VM_0_5_centos test]# cat 22.sh
#!/bin/bash
a=`echo $0 | sed 's/..\(...\).*/\1/'`
for i in `w|awk -v b=$a 'NR>2{if($NF !~ b) print $2}'`
do
echo $i
fuser -k /dev/$i
done [root@VM_0_5_centos test]# sh 22.sh
pts/0
/dev/pts/0: 978 3473 Connection closed by foreign host. Disconnected from remote host(tencentYun) at 15:31:30. Type `help' to learn how to use Xshell prompt.
23、设计一个shell程序,在每月第一天备份并压缩/etc目录的所有内容,
存放在/root/bak目录里,且文件名,为如下形式yymmdd_etc,yy为年,mm为月,dd为日。Shell程序fileback存放在/usr/bin目录下。
[root@VM_0_5_centos test]# vi 23.sh
[root@VM_0_5_centos test]# cat 23.sh
#!/bin/bash
#需要有root权限 filename=`date +%y%m%d`_etc.tar.gz
#cd /etc/
tar -zcvf $filename *
mv $filename /root/bak/ # vim /etc/crontab 加入
# * * 1 * * root ./23.sh &
# 加入定时管理模块
24、对于一个用户日志文件,每行记录了一个用户查询串,长度为1-255字节,共几千万行,请列出查询最多的前100条。
日志可以自己构造。 (提示:awk sort uniq head)
[root@VM_0_5_centos test]# mkdir -p 24
[root@VM_0_5_centos test]# r -y
-bash: r: command not found
[root@VM_0_5_centos test]# rz -E
rz waiting to receive.
[root@VM_0_5_centos test]# ll
total 24
-rw-r--r-- 1 root root 212 Aug 6 15:28 21.sh
-rw-r--r-- 1 root root 148 Aug 6 15:27 22.sh
-rw-r--r-- 1 root root 125 Aug 6 15:38 23.sh
drwxr-xr-x 2 root root 4096 Aug 6 15:39 24
-rw-r--r-- 1 root root 109 May 20 2015 24.sh
-rw-r--r-- 1 root root 2090 May 20 2015 testdata.txt
[root@VM_0_5_centos test]# mv 24.sh testdata.txt 24
[root@VM_0_5_centos test]# cd 24
[root@VM_0_5_centos 24]# ll
total 8
-rw-r--r-- 1 root root 109 May 20 2015 24.sh
-rw-r--r-- 1 root root 2090 May 20 2015 testdata.txt [root@VM_0_5_centos 24]# cat 24.sh
#! /bin/bash # show top 10 file=$1
awk '{print $1}' testdata.txt | sort | uniq -c | sort -k1nr | head -n10 [root@VM_0_5_centos 24]# sh 24.sh
13 廖铭杰
10 徐磊
3 刘刚
3 宋世达
3 熊鹏飞
1 丁俊龙
1 于仲
1 任凯
1 冯夏
1 冯宇鹏
25、编写自己的ubuntu环境安装脚本
26、编写服务器守护进程管理脚本。
27、查看TCP连接状态
netstat -nat |awk ‘{print $6}’|sort|uniq -c|sort -rn
netstat -n | awk ‘/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}’ 或
netstat -n | awk ‘/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}’
netstat -n | awk ‘/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"t",arr[k]}’
netstat -n |awk ‘/^tcp/ {print $NF}’|sort|uniq -c|sort -rn
netstat -ant | awk ‘{print $NF}’ | grep -v ‘[a-z]‘ | sort | uniq -c
28、查找请求数前20个IP(常用于查找攻来源):
[root@VM_0_5_centos 24]# vi 28.sh
[root@VM_0_5_centos 24]# cat 28.sh
echo "出现次数 IP地址"
echo "第一种方法:"
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
echo "第二种方法:"
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n20 [root@VM_0_5_centos 24]# sh 28.sh
出现次数 IP地址
第一种方法:
3 0.0.0.0
1 122.96.40.191
第二种方法:
3 0.0.0.0
1 122.96.40.191
29、用tcpdump嗅探80端口的访问看看谁最高
[root@VM_0_5_centos 24]# vi 29.sh
[root@VM_0_5_centos 24]# cat 29.sh
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20 [root@VM_0_5_centos 24]# sh 29.sh
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
30、查找较多time_wait连接
[root@VM_0_5_centos 24]# vi 30.sh
[root@VM_0_5_centos 24]# cat 30.sh
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20
[root@VM_0_5_centos 24]# sh 30.sh
1 193.201.224.232:8462
1 193.201.224.232:39595
获取脚本
注:所有脚本均可通过关注右侧公众号,后台回复"shell编程练习"获取百度网盘链接。
shell编程练习(三): 笔试21-30的更多相关文章
- shell编程练习(二): 笔试11-20
笔试练习(二): 11.写一个shell脚本来得到当前的日期,时间,用户名和当前工作目录. [root@VM_0_5_centos test]# vi 11.sh [root@VM_0_5_cento ...
- shell编程练习(一): 笔试1-10
笔试练习(一): 1.求2个数之和 [root@VM_0_5_centos test]# vi 1.sh [root@VM_0_5_centos test]# cat 1.sh #! /bin/sh ...
- 【shell】shell编程(三)-if,select,case语句
通过前两篇文章,我们掌握了shell的一些基本写法和变量的使用,以及基本数据类型的运算.那么,本次就将要学习shell的结构化命令了,也就是我们其它编程语言中的条件选择语句及循环语句. 不过,在学习s ...
- Linux下的shell编程(三)BY 四喜三顺
正则表达式:-------------------------------------------------------------------------------------------^ ...
- shell编程练习(四): 笔试31-68
笔试练习(四): 31.找查较多的SYN连接 netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uni ...
- [转]Windows Shell 编程 第三章 【转自:http://blog.csdn.net/wangqiulin123456/article/details/7987901】
第三章 操作文件 我依然清楚地记得,Windows95 的贝塔版出现的情形,它在朋友之间和学院中传播,好酷,全新的文件管理器,一种全图标,全彩色可客户化的界面,以及活泼的动画标识使得在文件拷贝和删除方 ...
- 小鸟初学Shell编程(三)脚本不同执行方式的影响
执行命令的方式 执行Shell脚本的方式通常有以下四种 方式一:bash ./test.sh 方式二:./test.sh 方式三:source ./test.sh 方式四:. ./test.sh 执行 ...
- shell编程基础(三): 位置参数与shell脚本的输入输出
一.位置参数和特殊变量 有很多特殊变量是被Shell自动赋值的,我们已经遇到了$?和$1,现在总结一下: 常用的位置参数和特殊变量: $0 相当于C语言main函数的argv[0] $1.$2... ...
- Shell编程(三)Shell特性
!$:显示上一条命令最后一个参数 $?: 上个命令的退出状态,或函数的返回值. alias xxx="命令":给命令取别名 xxx 通过 vim ~/.bashrc 里编辑,可以来 ...
随机推荐
- H5_ 多媒体video,autio使用示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [error] - Build path is incomplete. Cannot find class file for org/aspectj/weaver/refl
将本地仓库中mybatis 的jar 包删除,然后在eclipse 中右键工程选中 Maven->upgrade ..
- python从入门到实践-5章if语句
#!/user/bin/env python cars = ['audi','bmw','subaru','toyota']for car in cars: if car == 'bmw': prin ...
- redhat 6 红帽6 Linux 网络配置
[root@ORAMYSQL ~]# cd /etc/sysconfig/network-scripts/ 切换到网卡配置目录 [root@ORAMYSQL network-scripts]# vi ...
- 坦白说bug
安卓收藏他发的图片就可以在收藏里看到了哦 苹果直接搜索聊天记录就行了哦(人 •͈ᴗ•͈)۶♡♡比心心
- Android单元测试之一:基本概念
Android单元测试之一:基本概念 简单介绍 单元测试是应用程序测试策略中的基本测试,通过对代码进行单元测试,一方面可以轻松地验证单个单元的逻辑是否正确,另一方面在每次构建之后运行单元测试,可以快读 ...
- [Swift]LeetCode216. 组合总和 III | Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Java异常处理:给程序罩一层保险
文/沉默王二 人这一生,总会遇到一些不可预料的麻烦,这些麻烦可能会让我们遭受沉重的打击.为了减轻因此承受的负担,我们就会买保险. 本着负责任的态度,我们程序员在写代码的时候,都非常的严谨.但程序在运行 ...
- C# int数据类型呵呵
int16=short; int32=int; int64=long; Int16 值类型表示值介于 -32768 到 +32767 之间的有符号整数. Int32 值类型表示值介于 -2,147,4 ...
- HttpClientFactory与Steeltoe结合来完成服务发现
前言 上一篇说了一下用HttpClientFactory实现了简单的熔断降级. 这篇就来简单说说用HttpClientFactory来实现服务发现.由于标题已经好明显的说了Steeltoe 因此这里会 ...