2009/08/29

Unix-like系统用户交流信息的几个小命令



向系统所有在线用户发送消息:
$ wall [message]
如果想设定是否接收这个消息:
$ mesg [y|n]

向特定用户发送小心:
$ write user [ttyname]

$ talk person [ttyname] 
也可以通过mesg来设定。

当然还有选项更丰富的mail命令:
$ mail [-iInv ] [-s subject ] [-c cc-addr ] [-b bcc-addr ] to-addr... 
$ mail [-iInNv -f ] [name ] 
$ mail [-iInNv [-u user ] ]

--
Liu Lantao
Oak Pacific Interactive Corp. Ltd.
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/08/25

Google Sets is cool!

Use Google Sets to expand a list of a few items, into a list with many items. For example let's suppose you want a set (or list) of Star Wars characters, but can only think of a few. Enter a the ones you can think of, and Google sets will return a whole list.

links: http://labs.google.com/sets

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

How-to: disable the PING response.

To disable the PING response, add the following line to your init script for the network:
echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

To reenable the PING response do this:
echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all

To make the change PERMANENT add the following line to /etc/sysctl.conf:
net.ipv4.icmp_echo_ignore_all=1
and execute this command
sysctl -p

It is better to use firewall for these purposes, so that you can optionally enable ping from some systems, esp monitoring systems
iptables -t filter -I INPUT -p icmp --icmp-type echo-request -s monitoring_system -j ACCEPT
iptables -t filter -I INPUT -p icmp --icmp-type echo-request -j DROP

Just in case it's not obvious to iptables newbies, replace "monitoring_system" with the IP/range of the server(s) which should be able to ping the server. All other ping requests will be silenty dropped.



--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/08/14

sed -i 's/str1/rep1/;s/str2/rep2/;...;s/strN/repN/' urfile

sed -i 's/str1/rep1/;s/str2/rep2/;...;s/strN/repN/' urfile

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/08/07

Nginx访问日志统计:按时间计数

$ grep "GET / " access.log | awk '{print substr($4,2,14)}' | uniq -c

   4275 04/Aug/2009 14
  11484 04/Aug/2009 15
  10145 04/Aug/2009 16
   9718 04/Aug/2009 17
   7522 04/Aug/2009 18
   8169 04/Aug/2009 19
   8385 04/Aug/2009 20
   9033 04/Aug/2009 21
   8356 04/Aug/2009 22
   6144 04/Aug/2009 23
   3457 05/Aug/2009 00
   1698 05/Aug/2009 01
    853 05/Aug/2009 02
    534 05/Aug/2009 03
    393 05/Aug/2009 04
    380 05/Aug/2009 05
    725 05/Aug/2009 06
   1672 05/Aug/2009 07
   5352 05/Aug/2009 08
   6786 05/Aug/2009 09
   5742 05/Aug/2009 10
   5686 05/Aug/2009 11
   6102 05/Aug/2009 12
   5435 05/Aug/2009 13
   4852 05/Aug/2009 14
   4645 05/Aug/2009 15
   4911 05/Aug/2009 16
   4479 05/Aug/2009 17
   3816 05/Aug/2009 18
   3532 05/Aug/2009 19
   3645 05/Aug/2009 20
   3958 05/Aug/2009 21
   3864 05/Aug/2009 22
   2653 05/Aug/2009 23
   1531 06/Aug/2009 00
    775 06/Aug/2009 01
    449 06/Aug/2009 02
    256 06/Aug/2009 03
    222 06/Aug/2009 04
    234 06/Aug/2009 05
    393 06/Aug/2009 06
    966 06/Aug/2009 07
   2615 06/Aug/2009 08
   3456 06/Aug/2009 09
   3349 06/Aug/2009 10
   3496 06/Aug/2009 11
   3863 06/Aug/2009 12
   3362 06/Aug/2009 13
   3022 06/Aug/2009 14
   2937 06/Aug/2009 15
   3763 06/Aug/2009 16
   2893 06/Aug/2009 17
   2603 06/Aug/2009 18
   2757 06/Aug/2009 19
   3500 06/Aug/2009 20
   3931 06/Aug/2009 21
   3683 06/Aug/2009 22
   2400 06/Aug/2009 23
   1435 07/Aug/2009 00
    647 07/Aug/2009 01
    351 07/Aug/2009 02
    200 07/Aug/2009 03
    157 07/Aug/2009 04
    192 07/Aug/2009 05
    275 07/Aug/2009 06
    696 07/Aug/2009 07
   1937 07/Aug/2009 08
   2616 07/Aug/2009 09
   2677 07/Aug/2009 10
   2473 07/Aug/2009 11
   2541 07/Aug/2009 12
   2350 07/Aug/2009 13
   2161 07/Aug/2009 14
   1738 07/Aug/2009 15


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------