笔试练习(三):

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. Base64简单原理

    Base64要求把每三个8bit的字节转换为四个6bit的字节(即3*8 = 4*6 = 24) 1.例如我们有一个中文字符“中国(gb2312)”,转为十进制为:中-->54992,国--&g ...

  2. vue调用 Highcharts 实现多个数据可视化展示

    一创建一个 options.js 代码为: export const option1 = { bar: { title: { text: '珠海猪场' // 指定图表标题 }, credits: { ...

  3. php使用protobuf3

    protoc的介绍,安装 1.定义一个protoc 文件 示例:person.proto syntax="proto3"; //声明版本,3x版本支持php package tes ...

  4. 如何安装并且使用jmeter进行简单的性能测试

    Jmeter  介绍 Jmeter  是一款使用Java开发的,开源免费的,测试工具, 主要用来做功能测试和性能测试(压力测试/负载测试). 而且用Jmeter 来测试 Restful API, 非常 ...

  5. Android APK 瘦身 - JOOX Music项目实战

    导语 JOOX Music是腾讯海外布局的一个音乐产品,2014年发布以来已经成为5个国家和地区排名第一的音乐App.东南亚是JOOX Music的主要发行地区,由于JOOX Music所面对的市场存 ...

  6. [Swift]LeetCode526. 优美的排列 | Beautiful Arrangement

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  7. shell脚本中单双引号疑惑

    工作中常用到shell脚本,遇到了一个疑惑,求解.    常见的解释: 单引号字符串的限制: 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的: 单引号字串中不能出现单独一个的单引号(对单 ...

  8. ECMAScript5.1的运算符、类型转换总结

    一.运算符优先级 从高到低 运算符 说明 () 圆括号 . [] new(带参数列表) 字段访问.数组索引.new(带参数列表) () new(无参数列表) 函数调用,无参数列表 ++(后置递增) - ...

  9. qt QClipBoard

        部分思路借鉴这篇文章: Qt学习之路(55): 剪贴板操作     剪贴板,这个词相信大家都比较熟悉,比如使用offiece的时候就会有粘贴板,文本编辑的时候Ctrl+C和Ctrl+V的使用, ...

  10. java基础(十二 )-----Java泛型详解

    本文对java的泛型的概念和使用做了详尽的介绍. 概述 泛型在java中有很重要的地位,在面向对象编程及各种设计模式中有非常广泛的应用. 什么是泛型?为什么要使用泛型? 泛型,即“参数化类型”.一提到 ...