2010年9月1日星期三

ubuntu 10.04 上,透過 gmail 用命令列寄信

$ sudo apt-get install heirloom-mailx msmtp
$ vim ~/.mailrc

set from="YOURNAME@gmail.com (YOURNAME)"
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a gmail"

$ vim ~/.msmtprc

defaults
logfile /home/USER/msmtp.log

# gmail account
account gmail
auth on
host smtp.gmail.com
port 587
user YOURNAME@gmail.com
password YOURPASSWORD
from YOURNAME@gmail.com
tls on
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt

# set default account to use (not necessary with single account)
account default : gmail

$ chmod 600 ~/.msmtprc
$ echo "Hello, world!" | mail -s "Test from command line" -a attachment.txt somebody@somedomain.org


ssmtp也有相同作用, 但ssmtp會把帳密以明碼存在/etc/下,會增有gmail被帳號被盜。


參考
How To Use Gmail Account To Relay Email From a Shell Prompt
在 Ubuntu 8.04 上透過 gmail 用命令列寄信

2010年5月7日星期五

又一個訓唔著既晚上。唔同既係,今晚有雷雨上映。

狂風首先響起左前奏, 雨聲令我既注意力再度分散, 走左出去露台觀雨。雨似雨, 又不似雨。初聽之下,雨聲就是雨聲, 突然雨聲變了沙鎚聲,然後一下閃電, 又一下,就好像要說明佢係特別既。 不知何時,雨聲又變回雨聲。

回想最初對雨既印象,就係細個阿媽買左一套黃色既雨衣同雨BOOT, 但係等左好耐都無落雨。過左好似三年咁耐, 終於可以穿甲上陣。雖然同樣都係返學日,但係係雨水陪伴之下就變得有趣得多。雨聲就好似無數既朋友不斷同你傾計,你只要細心傾聽,就可以聽到佢地既言語。冰涼既雨水隔住雨衣都可以感受到,令夏日既刺熱感完全消退。青蛙既叫聲取代左吵耳既蟬聲,好似氣定神閒咁唱緊歌。雨聲又掩蓋左人們煩燥既談話聲,感覺就好似去左熱帶雨林,平時既不自覺既壓力消去得無影無終。我, 愛雨。

回到現實,蛙叫聲已經聽唔到, 換黎既黎低沈既船鳴聲, 可能它在悲叫吧? 在這七百萬人的都市中,也許只有我聽到, 但我又能做什麼? 破!! 突然雷聲一響,喝止了雨, 也喝止了夢。




又,雨停了又落, 就好似女人既心情咁, 永遠都睇唔通。

2009年7月25日星期六

Benchmarking php op-codes caches

1)No PHP op-code cache:

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   50.571265 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    59.32 [#/sec] (mean)
Time per request:       84.285 [ms] (mean)
Time per request:       16.857 [ms] (mean, across all concurrent requests)
Transfer rate:          332.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    30   83  47.7     73     322
Waiting:       30   81  47.3     70     322
Total:         30   83  47.7     73     322

Percentage of the requests served within a certain time (ms)
  50%     73
  66%     96
  75%    109
  80%    120
  90%    149
  95%    177
  98%    214
  99%    236
100%    322 (longest request)

2)Xcache:

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   4.970640 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    603.54 [#/sec] (mean)
Time per request:       8.284 [ms] (mean)
Time per request:       1.657 [ms] (mean, across all concurrent requests)
Transfer rate:          3378.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     2    7   4.1      7      48
Waiting:        2    7   4.1      7      47
Total:          2    7   4.1      7      48

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      9
  75%     10
  80%     10
  90%     12
  95%     15
  98%     18
  99%     21
100%     48 (longest request)

3)eAccelerator

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   6.9865 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    499.18 [#/sec] (mean)
Time per request:       10.016 [ms] (mean)
Time per request:       2.003 [ms] (mean, across all concurrent requests)
Transfer rate:          2794.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       9
Processing:     3    9   6.1      8      57
Waiting:        3    9   6.1      8      57
Total:          3    9   6.1      8      57

Percentage of the requests served within a certain time (ms)
  50%      8
  66%     10
  75%     12
  80%     13
  90%     18
  95%     22
  98%     26
  99%     30
100%     57 (longest request)

Xcache is the winner.

2009年7月16日星期四

mysql INSERT OR UPDATE

mysql 時,如果沒有 在primary_key 或unique有重覆時, 就會執行update 指令。
平時我都會先select count(1) 看看有沒有已存表格, 再分別insert 或 update, 今天才發現原來可以一句ko:

ON DUPLICATE KEY UPDATE


CREATE
TABLE ipstat(ip int UNSIGNED NOT NULL PRIMARY KEY, hits int UNSIGNED NOT NULL, last_hit timestamp);


INSERT
INTO ipstat VALUES(inet_aton('192.168.0.1'),1,now()) ON duplicate KEY UPDATE hits=hits+1;

2009年4月15日星期三

Kill Processes Quickly With PKILL

Kill Processes Quickly With PKILL

To kill a process I've always either used top, or the kill or killall commands along with ps|aux to discover process numbers/names. However, the pkill command removes a lot of work -- pkill firefox, for example, will search the list of processes for anything matching firefox, and then kill it (i.e. send a SIGTERM). pstree is also a pretty cool command, and will show all the processes in a family-tree arrangement, organized by who owns them."



From:
10 Expert Ubuntu Tricks - Business Center - PC World