perl学习笔记

2012.01.26
#!/usr/bin/perl -w
use strict;
#语法检查

printf "1234567890" x 7 . "\n";
#重复7次,也就是总共70列,后面的.是字符串连接符
my @lines=;
#从标准输入中读取数组,一般都是键盘,注意和<>的区别

foreach (@lines) {
my $lines=$_;
#定义标量,并把数组中的元素复制给$lines
chomp $lines;
#去掉数组元素的换行符,chomp的返回值是去掉的换行符的数量,一般都是1或者0
printf "%20s\n",$lines;
#打印从键盘输入的内容
}

改进过的:
#!/usr/bin/perl -w
use strict;
print "Please input scale:\n";
chomp(my $scale=);
#chomp,去掉了后面的换行符
printf "1234567890" x ($scale/10) . "\n";
#x后面的重复数字,会自动舍去小数,按整数计算

print "Please type long:\n";
chomp(my $long=);
$long=("%" . $long . "s" . "\n");
#这里的括号不能省略,省略了会产生歧义
my @lines=;
foreach (@lines) {
my $lines=$_;
#这里可以直接使用$_
chomp $lines;
#print $long;
printf $long,$lines;
}

zcat grep 提示 Binary file 1.txt matches

zcat /home/downfile/test.tar.gz | grep -a ‘key_name’ # -a : grep认为这是二进制文件

关于青春,关于人生

青春最重要的不是在那里度过 而是不后悔 每个人选择去哪里发展 怎样发展都是无可厚非的 只要知道自己要什么样的生活 北京是个好的发展平台 是高水准竞技场 在这里立足需要付出比在其他地方高出几倍的努力 但回报也是可观的 生活是平衡的 榨取你多少 就会回报你多少 无论选择什么 不后悔最重要

在64位的环境下编译32位的应用程序

在64位的环境下编译32位的应用程序
背景知识: http://www.divms.uiowa.edu/local/linux_help/rh_ws3_amd64_faq.html

我们的 64bit Debain 需要安装以下软件包

apt-get install ia32-libs libc6-dev-i386 linux32

1) 最关键的东西是需要告知gcc编译器编译的平台是 i386,CFLAGS 必须添加 -m32 参数. [关于gcc编译参数的官方文档]

2) 用 linux32 命令在configure改一下CHOST,设置一下编译环境

linux32 命令使用前后区别

staff-1:~/src/lame-3.96.1# ./configure
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu

staff-1:~/src/lame-3.96.1# linux32 ./configure
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu

3) 如果编译的程序是32位的,所需要的动态链接库也需重新编译,例如mplayer需要用到 mp3lame,jpeg-6b,libpng等,均需要重新编译.

4) 如何知道应用程序是64位还是32位的?可使用file命令查看.

staff-1:~# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), for GNU/Linux 2.6.0, stripped

staff-1:~# file /usr/bin/mplayer
/usr/bin/mplayer: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), for GNU/Linux 2.6.0, stripped

5) 一些编译前准备的实例,mplayer

linux32 ./configure –prefix=/usr –cc=”gcc -m32″ –target=”i386-linux”
make
make install

注意:-cc,–target 参数不一定每个 configure 程序都提供,需灵活变通,其本质是设置了一些环境变量,可用手动配置.

export CFLAGS=”-m32 -04 -march=i386 -mtune=i386″

6) 注意和原来的共享库冲突,尽量不要编译到 /usr 目录下,否则影响其它64位的程序正常运作就得不尝失了.

7) 能不能100%编译成功? 不一定,如果 makefile 使用了64位的linker例如ld等,去link你编译出来32位的so的话,那就会报告不兼容. Good luck!!

相关参考:
•How to build 32-bit Wine on a 64-bit (x86-64) system

以下是其它人的讨论

1) 最关键的东西是需要告知gcc编译器编译的平台是 i386,CFLAGS 必须添加 -m32 参数. [关于gcc编译参数的官方文档]

2) 用 linux32 命令在configure改一下CHOST,设置一下编译环境

linux32 命令使用前后区别

staff-1:~/src/lame-3.96.1# ./configure
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu

staff-1:~/src/lame-3.96.1# linux32 ./configure
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu

这段没看懂,
第2点怎么设置的能说具体点吗??谢谢。

答复:
linux32 是一个设置环境变量 CHOST 的命令.可用 export CHOST=”i686-pc-linux-gnu” 代替

我自己尝试编译libmm在64位服务器上通过,参数如下
./configure CC=”gcc -m32″

nagios,本地发送报警邮件超时问题

最近在外网新搭了一套nagios系统,开始几天系统出了问题nagios还能发邮件通知,可最近出了问题老收不到邮件,手工在服务器上发邮件又可以,后来一查sendmail的日志和nagios的日志,发现sendmail的邮件只有邮件信息,没有进邮件队列.nagios那边的日志又报下面的警告:

[1292174436] Warning: Contact ‘wahaha’ service notification command ‘/usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: /boot\nHost: hostname\nAddress: 192.168.3.11\nState: CRITICAL\n\nDate/Time: Mon Dec 13 01:20:05 CST 2010\n\nAdditional Info:\n\nDISK CRITICAL – free space: /boot
8 MB (8% inode=99%):” | /bin/mail -s “** PROBLEM Service Alert: hostname//boot is CRITICAL **” wahaha@163.com’ timed out after 30 seconds

从上面的日志看,应该是发送超时了,也就是说设置的通知时间还不够能让sendmail发出邮件的时间,到这就好办了.通过修改nagios的配置文件nagios.cfg,将notification_timeout=30改为notification_timeout=120后重起nagios.发现已经能收到报警邮件了,到此问题解决!

sshd超时断开问题

1、echo $TMOUT
如果显示空白,表示没有设置, 等于使用默认值0, 一般情况下应该是不超时. 如果大于0, 可以在如/etc/profile之类文件中设置它为0.
Definition: TMOUT: If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive

2、修改/etc/ssh/sshd_config文件,将ClientAliveInterval 0和ClientAliveCountMax 3的注释符号去掉,将ClientAliveInterval对应的0改成60,ClientAliveInterval指定了服务器端向客户端请求消息的时间间隔, 默认是0, 不发送.而ClientAliveInterval 60表示每分钟发送一次, 然后客户端响应, 这样就保持长连接了.ClientAliveCountMax, 使用默认值3即可.ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开. 正常情况下, 客户端不会不响应.

想参考更多,请输入man sshd_config了解更多信息

cacti的thold阀值单位

cacti的thold插件的带宽阀值的单位,配置时的单位应该是大bytes,字节,而不是位
也就是说带宽100M的阀值,其实是100x1024x1024/8
即阀值为:13107200

excel2007的选项位置

excel选项位置office 2007的excel选项在哪里?

万网15周年,logo都变了

让我说,在就该变了,以前的logo真丑,就像个乡巴佬,不知道大家有没有同感。

万网logo新

deflate ddos防火墙

linux下被ddos,如果你实在没办法,试试这个吧,也许能帮你忙

http://deflate.medialayer.com/

上面的防火墙上了,还是不行,继续研究
发现被ddos有个规律,一旦断网,服务器的php-cgi马上到100%,内网是通的,外网就断了
当php-cgi占用cpu下来时,网络通了,网站也能正常打开,于是有了下面的脚本
#!/bin/bash
while true
do

PIDS=`top -bn 1 | grep "^ *[1-9]" | awk '{ if ( $2 == "www" && $9>80 ) print $1}'`
for PID in $PIDS
do
kill $PID
done
sleep 10

done


京ICP备07010914号