Pages: 3/59 First page Previous page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]

use perl to get timestamp

[不指定 2009/10/30 08:48 | by askwan ]
in different  context have different value
eg:
saclar context
print scalar (localtime);

then output :
Thu Oct 29 18:50:01 2009

but in list context ;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$sec    0 ~ 59
$min    0 ~ 59
$hour  0 ~ 23
$mday   1~31
$mon     0 ~ 11
$year   after 1900,it passed years
$wday    0 ~ 6
$yday    0 ~365
$isdst   insignificant for me

can use this to get timestamp

output:
2009-10-29 19:2:40

have some defect ablove,use this

output:
2009-10-29 19:02:45

you can also use POSIX functions:
eg


output:
2009-10-29 11:10:44
2009-10-29 19:10:44
first, install  DBI and DBD::Pg module

come next two example I have writen for testing:

example one:


example two:
output :
datname             blks_read           blks_hit            
------------------------------------------------------------
template1           0                   0                  
template0           0                   0                  
postgres            136                 5955                
askwan              124                 7396
        

compile net-snmp on debian lenny

[不指定 2009/09/23 16:16 | by askwan ]
net-snmp
下载地址:http://ncu.dl.sourceforge.net/project/net-snmp/net-snmp/5.4.2.1/net-snmp-5.4.2.1.tar.gz
解压然后编译,编译参数
./configure --prefix=/usr/local/net-snmp/ --with-sys-contact="askwan@askwan.com" --with-sys-location="pudong shanghai China" --enable-shared --with-default-snmp-version=2 --enable-mfd-rewrites --with-mib-modules="misc/ipfwacc mibII host disman/event-mib ucd_snmp agent_mibs agentx notification target utilities ucd-snmp/diskio tunnel mibII/mta_sendmail" --with-sysconfdir="/usr/local/net-snmp/etc/"

如编译报错:
Quotation
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status

这是缺少libperl-dev开发库,安装上
apt-get install libperl-dev

然后make ;make install
可以用snmpconf配置snmpd.conf,也可用例子文件
cp  EXAMPLE.conf /usr/local/net-snmp/etc/snmpd.conf

然后根据需要修改此文件
com2sec local     localhost       askwan
com2sec mynetwork 192.168.0.0/24      askwan

group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork

view all    included  .1                               80
access MyROGroup ""      any       noauth    exact  all    none   none
access MyRWGroup ""      any       noauth    exact  all    all    none

syslocation shanghai pu dong
syscontact Me askwan@askwan.com

启动
/usr/local/net-snmp/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -c /usr/local/net-snmp/etc/snmpd.conf


测试
snmpwalk -c askwan -v2c 192.168.0.5 if

Quotation
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
....


---------END------------
Tags: ,
Pages: 3/59 First page Previous page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]