shell编程练习(四): 笔试31-68
笔试练习(四):
31、找查较多的SYN连接
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more
32、根据端口列进程
netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1
33、获得访问前10位的ip地址
cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'
34、访问次数最多的文件或页面,取前20
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20
35、列出传输最大的几个exe文件(分析下载站的时候常用)
cat access.log |awk '($7~/.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -20
36、列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数
cat access.log |awk '($10 > 200000 && $7~/.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -100
37、如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面
cat access.log |awk '($7~/.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100
38、列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cat access.log |awk '($NF > 60 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
39、列出传输时间超过 30 秒的文件
cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20
40、统计网站流量(G)
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'
41、统计404的连接
awk F($9 ~/404/)' access.log | awk '{priFnt $9,$7}' | sort
42、统计http status
cat access.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn
43、蜘蛛分析,查看是哪些蜘蛛在抓取内容。
/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'
44、创建一个用户mandriva,其ID号为2002,基本组为distro(组ID为3003),附加组为linux;
# groupadd linux
# groupadd -g 3003 distro
# useradd -u 2002 -g distro -G linux mandriva
45、创建一个用户fedora,其全名为Fedora Community,默认shell为tcsh;
# useradd -c "Fedora Community" -s /bin/tcsh fedora
46、修改mandriva的ID号为4004,基本组为linux,附加组为distro和fedora;
# usermod -u 4004 -g linux -G distro,fedora mandriva
47、给fedora加密码,并设定其密码最短使用期限为2天,最长为50天;
# passwd fedora
# chage -m 2 -M 50 fedora
48、调试命令
strace -p pid
49、写一个脚本
1、创建一个组newgroup, id号为4000;
2、创建一个用户mageedu1, id号为3001,附加组为newgroup;
3、创建目录/tmp/hellodirxyz
4、复制/etc/fstab至上面的目录中
5、改变目录及内部文件的属主和属组为mageedu1;
6、让目录及内部文件的其它用户没有任何权限; #!/bin/bash
# Description:
# Version:
# Datetime:
# Author: myGroup="newgroup1"
myUser="mageedu2"
myDir="/tmp/hellodirxyz1"
myID=3002 groupadd -g 4001 $myGroup
useradd -u $myID -G $myGroup $myUser
mkdir $myDir
cp /etc/fstab $myDir
chown -R $myUser:$myUser $myDir
chmod -R o= $myDir unset myGroup myUser myID myDir
50、统计/bin、/usr/bin、/sbin和/usr/sbin等各目录中的文件个数;
# ls /bin | wc -l
51、显示当前系统上所有用户的shell,要求,每种shell只显示一次;
# cut -d: -f7 /etc/passwd | sort -u
52、取出/etc/passwd文件的第7行;
# head -7 /etc/passwd | tail -1
53、显示第3题中取出的第7行的用户名;
# head -7 /etc/passwd | tail -1 | cut -d: -f1 # head -7 /etc/passwd | tail -1 | cut -d: -f1 | tr 'a-z' 'A-Z'
54、统计/etc目录下以P或p开头的文件个数;
# ls -d /etc/[Pp]* | wc -l
55、写一个脚本,用for循环实现显示/etc/init.d/functions、/etc/rc.d/rc.sysinit和/etc/fstab各有多少行;
for fileName in /etc/init.d/functions /etc/rc.d/rc.sysinit /etc/fstab; do
wc -l $fileName
done #!/bin/bash
for fileName in /etc/init.d/functions /etc/rc.d/rc.sysinit /etc/fstab; do
lineCount=`wc -l $fileName | cut -d' ' -f1`
echo "$fileName: $lineCount lines."
done #!/bin/bash
for fileName in /etc/init.d/functions /etc/rc.d/rc.sysinit /etc/fstab; do
echo "$fileName: `wc -l $fileName | cut -d' ' -f1` lines."
done
56、写一个脚本,将上一题中三个文件的复制到/tmp目录中;用for循环实现,分别将每个文件的最近一次的修改时间改为2016年12月15号15点43分;
for fileName in /etc/init.d/functions /etc/rc.d/rc.sysinit /etc/fstab; do
cp $fileName /tmp
baseName=`basename $fileName`
touch -m -t 201109151327 /tmp/$baseName
done
57、写一个脚本, 显示/etc/passwd中第3、7和11个用户的用户名和ID号;
for lineNo in 3 7 11; do
userInfo=`head -n $lineNo /etc/passwd | tail -1 | cut -d: -f1,3`
echo -e "User: `echo $userInfo | cut -d: -f1`\nUid: `echo $userInfo |cut -d: -f2`"
done
58、显示/proc/meminfo文件中以大小写s开头的行;
# grep "^[sS]" /proc/meminfo
# grep -i "^s" /proc/meminfo
59、取出默认shell为非bash的用户;
# grep -v "bash$" /etc/passwd | cut -d: -f1
60、取出默认shell为bash的且其ID号最大的用户;
# grep "bash$" /etc/passwd | sort -n -t: -k3 | tail -1 | cut -d: -f1
61、显示/etc/rc.d/rc.sysinit文件中,以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.sysinit
62、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
# grep "^[[:space:]]\{1,\}[^[:space:]]\{1,\}" /boot/grub/grub.conf
63、找出/etc/passwd文件中一位数或两位数;
# grep --color=auto "\<[0-9]\{1,2\}\>" /etc/passwd
64、找出ifconfig命令结果中的1到255之间的整数;
# ifconfig | grep -E --color=auto "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
65、查看当前系统上root用户的所有信息;
# grep "^root\>" /etc/passwd
66、添加用户bash和testbash、basher,而后找出当前系统上其用户名和默认shell相同的用户;
# grep --color=auto "^\([[:alnum:]]\{1,\}\)\>.*\1$" /etc/passwd
67、找出netstat -tan命令执行的结果中以“LISTEN”或“ESTABLISHED”结尾的行;
68、取出当前系统上所有用户的shell,要求:每种shell只显示一次,且按升序显示;
# cut -d: -f7 /etc/passwd | sort -u
shell编程练习(四): 笔试31-68的更多相关文章
- shell编程练习(三): 笔试21-30
笔试练习(三): 21.编写shell程序,实现自动删除30个账号的功能. 账号名为std01至std30. [root@VM_0_5_centos test]# vi 21.sh [root@VM_ ...
- 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编程(四)管道符
管道作用 管道实际上就是进程之间的一个通信工具,那么用在Linux命令中主要是方便两条命令互相之间可以相互通信. 管道符 管道符(匿名管道)是Shell编程经常用到的通信工具. 管道符是"| ...
- [转]Windows Shell 编程 第四章 【来源 http://blog.csdn.net/wangqiulin123456/article/details/7987933】
第四章 文件的本质 以前,所有文件和目录都有一个确定的属性集:时间,日期,尺寸,以及表示‘只读的’,‘隐藏的,‘存档的’,或‘系统的’状态标志.然而,Windos95(及后来的WindowsNT4.0 ...
- 【shell】shell编程(四)-循环语句
上篇我们学习了shell中条件选择语句的用法.接下来本篇就来学习循环语句.在shell中,循环是通过for, while, until命令来实现的.下面就分别来看看吧. for for循环有两种形式: ...
- shell编程基础(四): shell脚本语法之函数及调试
一.Shell脚本中的函数 和C语言类似,Shell中也有函数的概念,但是函数定义中没有返回值也没有参数列表.例如: #! /bin/sh fun(){ echo "Function fun ...
- Shell编程(四)Shell变量
1. 自定义变量(仅在当前shell生效) 1.1 定义变量 #!/usr/bin/bash ip=115.239.210.27 if ping -c1 $ip &>/dev/null ...
- shell编程第四天
随机推荐
- 201771010118 马昕璐《面向对象程序设计java》第十周学习总结
第一部分:理论知识学习部分 泛型:也称参数化类型(parameterized type)就是在定义类.接口和方法时,通过类型参数 指示将要处理的对象类型. 泛型程序设计(Generic program ...
- 用cmd命令执行SQL脚本
1.简单说明 osql 为SQL Server的命令 2.要在cmd中执行该命令,一般安装SQL Server后该命令对应的路径会自动添加到系统环境变量中. 3.-S 表示要连接的数据库 -U表示登录 ...
- JavaScript经典作用域问题(转载)
题目 var a = 10; function test(){ a = 100; console.log(a); console.log(this.a); var a; console.log(a); ...
- mysql uodate 报错 You can't specify target table '**' for update in FROM clause
You can't specify target table 'sc' for update in FROM clause 背景:把“sc”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩: 上面 ...
- MS SQL计算最大公约数和最小公倍数函数
/*求两个数的最大公约数*/ CREATE FUNCTION f_GetGys ( @num1 BIGINT , @num2 BIGINT ) RETURNS BIGINT AS BEGIN DECL ...
- js-day06-jQuery事件和DOM操作-练习题
jQuery事件绑定 js中绑定事件,三种方式: 方式1: 直接在元素上,增加onXxx事件属性. <button onclick="alert(1);">点我< ...
- emWin万年历,含uCOS-III和FreeRTOS两个版本
第8期:万年历配套例子:V6-914_STemWin提高篇实验_万年历(uCOS-III)V6-915_STemWin提高篇实验_万年历(FreeRTOS) 例程下载地址: http://forum. ...
- [Swift]LeetCode250.计数相同值子树的个数 $ Count Univalue Subtrees
Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...
- [Swift]LeetCode335. 路径交叉 | Self Crossing
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to th ...
- [Swift]LeetCode980. 不同路径 III | Unique Paths III
On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square. There is e ...