记一次捉急的文本处理

2014-02-19 by Brant Xiong

前言

今天要需要统计10w个query的页面构成,由于输入文件格式不标准,url编码不统一等各种问题,整个统计过程相当纠结...下面将其中的一些点记录下来,供以后参考

异常文件处理

删除文件最后的异常行:

for file in `ls`; do line=`tail -1 $file`; if [ "$line" != "}," ]; then sed -i '$d' $file;fi;done

删除目录下的空文件:

find -maxdepth 1 -type f -empty -print0 | xargs -0 rm -f

python处理url

从url中获取domain name:

1
2
3
4
5
6
#!/usr/bin ...
read more

tcpdump用法简介

2014-02-18 by Brant Xiong

前言

今天在追查问题时,需要转包分析,用到了tcpdump工具,下面做下记录~

基本用法

tcpdump 采用命令行方式,需以root权限运行,它的命令格式为:

tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ]
        [ -i 网络接口 ] [ -r 文件名] [ -s snaplen ]
        [ -T 类型 ] [ -w 文件名 ] [表达式 ]

简单用法:

tcpdump -i eth1 port 8001
#查看localhost数据包
tcpdump -i lo port 8001

将结果写入文件:

tcpdump -i lo -nn port 8001 -w dump

显示http header ...

read more

Memcached和Redis基础

2014-02-17 by Brant Xiong

本文主要介绍Memcached和Redisd的使用基础

Memcached安装和使用

sudo apt-get install memcached
sudo apt-get install php-pecl-memcache
memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid

参数说明:

-d 启动一个守护进程
-p 端口
-m 分配的内存是M
-c 最大运行并发数
-P memcache的pid

php使用代码:

<?php
$memcache = new Memcache;
$memcache -> connect('127.0.0.1', 11211);
$memcache ...
read more

利用tc工具做限速

2014-02-17 by Brant Xiong

前言

有关tc的介绍,可以参见tc

tc的使用

tc封装的脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
#a simple example for "tc"
#set the param
PORT=$2
DELAY ...
read more

Ubuntu10.04 VPS配置(一)基础环境篇

2014-02-17 by Brant Xiong

VPS介绍

增加非root用户

当以root权限登陆一台全新的VPS之后,第一件事情就是增加拥有sudo权限的非root用户,目的如下: - it prevents the user making any system-destroying mistakes - it stores all the commands run with sudo to a file where can be reviewed later if needed

增加用户

   sudo ...
read more
Follow me on GitHub