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 里编辑,可以来 ...
随机推荐
- RHEL系统初始化步骤
1.配置网络 ##初始化网络(可在虚拟网络编辑器查看自己的网段) ##方法一:静态初始化 read -p "输入你当前Linux的IP地址:" ip ETH=` ifconfig ...
- Java_接口与抽象类
接口: 接口,英文interface,在java中,泛指供别人调用的方法或函数.接口是对行为的一种抽象. 语法: [public] interface InterfaceName{} 注意: 1)接口 ...
- 动态设置bootstrapswitch状态
checkbox的html <input type="checkbox" name="mySwitch" id="mySwitch"& ...
- extremecomponents
具体教程: http://www.cnblogs.com/QQParadise/articles/1488920.html 教程中涉及到springmvc的相关知识 下载地址:http://sourc ...
- SecureCRT连接虚拟机失败及虚拟机ping不通外网
背景: VMware上安装了centos,从学校的网络换到了家里后,用SecureCRT登录时发现 connection closed,然后在虚拟机里发现ping不通外网了,ping虚拟机IP是通的. ...
- 问题:这个新申请的内存为什么不能free掉?(已解决)
一.问题描述 先上代码, /*** 省略 ***/ uChar *base64 = NULL; /*** 省略 ***/ base64 = (一段内存) /*** 省略 ***/ base64 = s ...
- HTML5 部分新增语义化标签元素
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- win10常用详细快捷键大全
• 贴靠窗口:Win +左/右> Win +上/下>窗口可以变为1/4大小放置在屏幕4个角落• 切换窗口:Alt + Tab(不是新的,但任务切换界面改进)• 任务视图:Win + Tab ...
- mysql5.7忽略大小写问题
mysql5.7忽略大小写问题 1.1 前言 新安装mysql5.7版本后,linux环境下默认是大小写敏感的. 1.2 忽略大小写敏感步骤 进入mysql配置文件: vi /et ...
- Array.from();Object.keys();Array.map()
Array.from():方法从一个类似数组或可迭代对象创建一个新的数组形式: const bar = ["a", "b", "c"]; A ...