笔试练习(三):

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的更多相关文章

  1. shell编程练习(二): 笔试11-20

    笔试练习(二): 11.写一个shell脚本来得到当前的日期,时间,用户名和当前工作目录. [root@VM_0_5_centos test]# vi 11.sh [root@VM_0_5_cento ...

  2. 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 ...

  3. 【shell】shell编程(三)-if,select,case语句

    通过前两篇文章,我们掌握了shell的一些基本写法和变量的使用,以及基本数据类型的运算.那么,本次就将要学习shell的结构化命令了,也就是我们其它编程语言中的条件选择语句及循环语句. 不过,在学习s ...

  4. Linux下的shell编程(三)BY 四喜三顺

    正则表达式:-------------------------------------------------------------------------------------------^   ...

  5. shell编程练习(四): 笔试31-68

    笔试练习(四): 31.找查较多的SYN连接 netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uni ...

  6. [转]Windows Shell 编程 第三章 【转自:http://blog.csdn.net/wangqiulin123456/article/details/7987901】

    第三章 操作文件 我依然清楚地记得,Windows95 的贝塔版出现的情形,它在朋友之间和学院中传播,好酷,全新的文件管理器,一种全图标,全彩色可客户化的界面,以及活泼的动画标识使得在文件拷贝和删除方 ...

  7. 小鸟初学Shell编程(三)脚本不同执行方式的影响

    执行命令的方式 执行Shell脚本的方式通常有以下四种 方式一:bash ./test.sh 方式二:./test.sh 方式三:source ./test.sh 方式四:. ./test.sh 执行 ...

  8. shell编程基础(三): 位置参数与shell脚本的输入输出

    一.位置参数和特殊变量 有很多特殊变量是被Shell自动赋值的,我们已经遇到了$?和$1,现在总结一下: 常用的位置参数和特殊变量: $0 相当于C语言main函数的argv[0] $1.$2... ...

  9. Shell编程(三)Shell特性

    !$:显示上一条命令最后一个参数 $?: 上个命令的退出状态,或函数的返回值. alias xxx="命令":给命令取别名 xxx 通过 vim ~/.bashrc 里编辑,可以来 ...

随机推荐

  1. Java中死锁的定位与修复

    死锁应该可以说是并发编程中比较常见的一种情况,可以说如果程序产生了死锁那将会对程序带来致命的影响:所以排查定位.修复死锁至关重要: 我们都知道死锁是由于多个对象或多个线程之间相互需要对方锁持有的锁而又 ...

  2. 借助Docker单机秒开数十万TCP连接

    熟悉网络编程的都清楚系统只有65535个端口可用,1024以下的端口为系统保留,所以除去系统保留端口后可用的只有65411个端口,而一个TCP连接由TCP四元组(源IP.源端口.TCP.目标IP.目标 ...

  3. linux系统做raid

    raid 常用步骤 1.ctrl+R 进入raid设置界面 2.F2 相当于右键功能 3.箭头 → 是下一个选项功能 4.ctrl+n是下一页,ctrl+p是前一页 5.Esc退出.最后ctrl+al ...

  4. node koa2 玩起来都是中间件啊

    玩的我想吐 !!! 整理下常用的中间件吧! 先列在这有空把这些中间件的使用技巧也写出来分享一下koa-router 路由中间件koa-bodyparser   POST数据处理的中间件koa-stri ...

  5. 使用SSM重新开发计科院网站

    一.游览 在游览器地址栏输入:http://localhost:8080/index,即访问计科院首页,由于前期对数据库以及JavaBean的设计考虑不够充分,导致后期的代码臃肿,所以项目启动时对首页 ...

  6. TCP协议学习总结(中)

    很多人都说TCP协议是一个十分复杂的协议,在学习当中,我对协议每一个问题都分解学习后,每一个分解我都能体会和理解它的要点,并不难理解.但我把这些拆分的细节合并后,确认感觉这样一个协议相对“臃肿”但又好 ...

  7. 如何在微信小程序定义全局变量、全局函数、如何实现 函数复用 模块化开发等问题详解

    1.如何定义全局数据 在app.js的App({})中定义的数据或函数都是全局的,在页面中可以通过var app = getApp();  app.function/key的方式调用,不过我们没有必要 ...

  8. [Swift]LeetCode977. 有序数组的平方 | Squares of a Sorted Array

    Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...

  9. Unable to preventDefault inside passive event listener due to target being treated as passive

    Unable to preventDefault inside passive event listener due to target being treated as passive 今天在做项目 ...

  10. Saiku设置展示table数据不隐藏空的行数据信息(二十六)

    Saiku设置展示table数据不隐藏空的行数据信息 saiku有个 非空的字段 按钮,点击这个后,会自动的把空的行数据信息给隐藏掉,这里我们来设置一下让其行数据不隐藏,为空的就为空. 主要更改两个文 ...