cl.pocari.org https://cl.pocari.org/ chalow を使用した ChangeLog メモ.主に技術的な話題とか. ja 2018-01-07T10:36:54+09:00 PHP の error_log に syslog を指定した際に他のログと混ざらないようにする https://cl.pocari.org/2013-08-30-1.html PHP のランタイムのエラーログですが、ファイルを指定するより syslog 経由にしたほうが何かと楽です。ファイルの場合は、ユーザ権限で実行している cli でのエラーと httpd でのエラーの両方を記録するために、パーミッションをもしかしたら 777 とかにする必要があるかもしれませんが、syslog の場合は特にそんなこと気にする必要がありません。php.ini で下記の設定をするだけなのですが、これだけだとちょっと都合が悪いです。sudo vim /etc/php.inierror_log = syslogというのも送信されるログのファシリティは user なので、例えば CentOS 6 だと /var/log/messages に出力されます。他のログと混ざるので都合が悪いです。じゃあ、ということで user.* を全部受けると、例えば yum でのインストールログも出力されるのでこれまた都合が悪いです。で、本題ですがファシリティが user かつタグ (プログラム名) が httpd (mod_php) または php (cli) の場合だけ専用のログに出力するようにします。一見めんどくさそうですが、CentOS 6 デフォルトの rsyslog だと、比較的簡単に設定できます。sudo vim /etc/rsyslog.d/php.conf$Umask 0000$RepeatedMsgReduction off$FileCreateMode 0644$template php_log,"/var/log/php.log"if ($syslogfacility-text == 'user') and \ (($programname == 'httpd') or ($programname == 'php')) then \ -?php_logsudo /etc/init.d/rsyslog restartで、syslog 経由なので、ログローテートも /etc/logrotate.d/syslog に /var/log/php.log を書いておけば OK です。 SUNAOKA Norifumi 2013-08-30T23:59:59+09:00 ファイルの場合は、ユーザ権限で実行している cli でのエラーと httpd でのエラーの両方を記録するために、
パーミッションをもしかしたら 777 とかにする必要があるかもしれませんが、
syslog の場合は特にそんなこと気にする必要がありません。

php.ini で下記の設定をするだけなのですが、これだけだとちょっと都合が悪いです。

sudo vim /etc/php.ini

error_log = syslog


というのも送信されるログのファシリティは user なので、例えば CentOS 6 だと /var/log/messages に出力されます。
他のログと混ざるので都合が悪いです。

じゃあ、ということで user.* を全部受けると、例えば yum でのインストールログも出力されるのでこれまた都合が悪いです。

で、本題ですがファシリティが user かつタグ (プログラム名) が httpd (mod_php) または php (cli) の場合だけ専用のログに出力するようにします。
一見めんどくさそうですが、CentOS 6 デフォルトの rsyslog だと、比較的簡単に設定できます。

sudo vim /etc/rsyslog.d/php.conf

$Umask 0000
$RepeatedMsgReduction off

$FileCreateMode 0644
$template php_log,"/var/log/php.log"

if ($syslogfacility-text == 'user') and \
   (($programname == 'httpd') or ($programname == 'php')) then \
       -?php_log

sudo /etc/init.d/rsyslog restart

で、syslog 経由なので、ログローテートも /etc/logrotate.d/syslog に /var/log/php.log を書いておけば OK です。
]]> Mac OS X 10.8 Mountain Lion + Eclipse で Scala 開発環境を作るメモ https://cl.pocari.org/2013-04-03-1.html いつもすぐ忘れるのでメモ。1. Eclipse 3.7.3 (Indigo) のインストール Eclipse 3.7 (Indigo) をダウンロード。パッケージは好みだけど、Eclipse Classic をダウンロードしてる。 なお、4.2 (Juno) ではなく、3.7 (Indigo) を使う理由は単に Indigo のほうがもっさりしていないから。 ダウンロードしたファイルを展開して、/Application にコピー。 プロジェクト毎に、Eclipse を使い分けるようにしているので、/Application/eclipse/eclipse-3.7.2_<プロジェクト名&gt; のようにしている。2. Scala-IDE をインストール Eclipse の [Help]-[Install New Software...] から普通にインストール。 Scala 2.9.x を使う場合は、下記を指定。http://download.scala-ide.org/sdk/e37/scala29/stable/site Scala 2.10.x を使う場合は、下記を指定。http://download.scala-ide.org/sdk/e37/scala210/stable/site インストールするパッケージは、下記だけ。・Scala IDE for Eclipse・ScalaTest for Scala IDE- refs.: Scala IDE for Eclipse http://scala-ide.org/- refs.: Download the 3.0 Release of the Scala IDE for Eclipse - Scala IDE for Eclipse http://scala-ide.org/download/current.html3. Eclipse Marketplace Client のインストール Eclipse Marketplace は、プラグインの検索とインストールができるサイト。そのクライアントをインストールする。 Eclipse の [Help]-[Install New Software...] からIndigo - http://download.eclipse.org/releases/indigo を選択して、「Marketplace Client」で検索しインストールする。- refs.: Introducing the Eclipse Marketplace Client | Eclipse Plugins, Bundles and Products - Eclipse Marketplace http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=10124. Subversive - SVN Team Provider (+ SVN Kit) のインストール (Subversion を使う場合) ちなみに、git を使う場合は、EGit とか使わないで、コマンドラインか SourceTree を使ってる。 Eclipse の [Help]-[Eclipse Marketplace...] で、「Subversive」を検索しインストール。 本体と、Localization だけ選択。 インストール後、再起動するとコネクタのインストール画面が出るので、使用する Subversion のバージョンに合わせた SVN Kit をインストールする。5. Glance プラグインのインストール インクリメンタルサーチの Glance プラグインをインストールする。 これは、Marketplace からインストールする。- refs.: Glance - Eclipse plug-in providing extensible useful incremental text search in Eclipse http://ystrot.github.com/glance/- refs.: Eclipseを改善するインクリメンタルサーチプラグイン「Glance」がオススメ! http://did2memo.net/2012/11/06/eclipse-iterative-search-plugin-glance/6. ER Master のインストール ER図が書けるプラグインの ER Master をインストールする。 Eclipse の [Help]-[Install New Software...] から普通にインストール。 Update Site には、下記を指定する。http://ermaster.sourceforge.net/update-site/- refs.: ER Master http://ermaster.sourceforge.net/index_ja.html7. プロパティー・エディターのインストール properties ファイルを自動で native2ascii してくれるプロパティー・エディターをインストール。 これも、Marketplace からインストールできる。 Marketplace Client で properties で検索し「プロパティー・エディター」をインストールする。8. Pleiades で日本語化する 不要であればこれは省略。OSX の場合はちょっと面倒。 まず、http://mergedoc.sourceforge.jp/ から、Pleiades プラグインをダウンロードする。 ここでは、1.4.x をダウンロードする。 ダウンロードしたファイルを展開してできた、pleiades ディレクトリを Eclipse をインストールしたディレクトリの dropins にコピーする。 つまり、dropins/pleiades になるようにする。 次に、eclipse.ini (/Applications/eclipse/eclipse-xxxxx/Eclipse.app/Contents/MacOS/eclipse.ini) の最終行に下記を追加。-javaagent:../../../dropins/pleiades/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar 最後に、Eclipse を -clean オプション付きで起動する。$ /Applications/eclipse/eclipse-xxxxx/eclipse -clean なお、Pleiades で日本語化した場合は、プラグインをインストールするたびに、-clean オプションで起動したほうがいい。 なので、いろいろプラグインをインストールした最後に日本語化したほうがいいような気がします。 SUNAOKA Norifumi 2013-04-03T23:59:59+09:00

1. Eclipse 3.7.3 (Indigo) のインストール

   Eclipse 3.7 (Indigo) をダウンロード。パッケージは好みだけど、Eclipse Classic をダウンロードしてる。
   なお、4.2 (Juno) ではなく、3.7 (Indigo) を使う理由は単に Indigo のほうがもっさりしていないから。

   ダウンロードしたファイルを展開して、/Application にコピー。
   プロジェクト毎に、Eclipse を使い分けるようにしているので、/Application/eclipse/eclipse-3.7.2_<プロジェクト名> のようにしている。

2. Scala-IDE をインストール

   Eclipse の [Help]-[Install New Software...] から普通にインストール。
   Scala 2.9.x を使う場合は、下記を指定。

http://download.scala-ide.org/sdk/e37/scala29/stable/site

   Scala 2.10.x を使う場合は、下記を指定。

http://download.scala-ide.org/sdk/e37/scala210/stable/site

   インストールするパッケージは、下記だけ。
・Scala IDE for Eclipse
・ScalaTest for Scala IDE

- refs.: Scala IDE for Eclipse
  http://scala-ide.org/

- refs.: Download the 3.0 Release of the Scala IDE for Eclipse - Scala IDE for Eclipse
  http://scala-ide.org/download/current.html

3. Eclipse Marketplace Client のインストール

   Eclipse Marketplace は、プラグインの検索とインストールができるサイト。そのクライアントをインストールする。
   Eclipse の [Help]-[Install New Software...] から

Indigo - http://download.eclipse.org/releases/indigo

  を選択して、「Marketplace Client」で検索しインストールする。

- refs.: Introducing the Eclipse Marketplace Client | Eclipse Plugins, Bundles and Products - Eclipse Marketplace
  http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=1012

4. Subversive - SVN Team Provider (+ SVN Kit) のインストール (Subversion を使う場合)

   ちなみに、git を使う場合は、EGit とか使わないで、コマンドラインか SourceTree を使ってる。

   Eclipse の [Help]-[Eclipse Marketplace...] で、「Subversive」を検索しインストール。
   本体と、Localization だけ選択。
   インストール後、再起動するとコネクタのインストール画面が出るので、使用する Subversion のバージョンに合わせた SVN Kit をインストールする。

5. Glance プラグインのインストール

   インクリメンタルサーチの Glance プラグインをインストールする。
   これは、Marketplace からインストールする。

- refs.: Glance - Eclipse plug-in providing extensible useful incremental text search in Eclipse
  http://ystrot.github.com/glance/

- refs.: Eclipseを改善するインクリメンタルサーチプラグイン「Glance」がオススメ!
  http://did2memo.net/2012/11/06/eclipse-iterative-search-plugin-glance/

6. ER Master のインストール

   ER図が書けるプラグインの ER Master をインストールする。
   Eclipse の [Help]-[Install New Software...] から普通にインストール。
   Update Site には、下記を指定する。

http://ermaster.sourceforge.net/update-site/

- refs.: ER Master
  http://ermaster.sourceforge.net/index_ja.html

7. プロパティー・エディターのインストール

   properties ファイルを自動で native2ascii してくれるプロパティー・エディターをインストール。
   これも、Marketplace からインストールできる。
   Marketplace Client で properties で検索し「プロパティー・エディター」をインストールする。

8. Pleiades で日本語化する

   不要であればこれは省略。OSX の場合はちょっと面倒。

   まず、http://mergedoc.sourceforge.jp/ から、Pleiades プラグインをダウンロードする。
   ここでは、1.4.x をダウンロードする。
   ダウンロードしたファイルを展開してできた、pleiades ディレクトリを Eclipse をインストールしたディレクトリの dropins にコピーする。
   つまり、dropins/pleiades になるようにする。

   次に、eclipse.ini (/Applications/eclipse/eclipse-xxxxx/Eclipse.app/Contents/MacOS/eclipse.ini) の最終行に下記を追加。

-javaagent:../../../dropins/pleiades/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar

   最後に、Eclipse を -clean オプション付きで起動する。

$ /Applications/eclipse/eclipse-xxxxx/eclipse -clean

  なお、Pleiades で日本語化した場合は、プラグインをインストールするたびに、-clean オプションで起動したほうがいい。
  なので、いろいろプラグインをインストールした最後に日本語化したほうがいいような気がします。
]]> JavaScript で数字を 3 桁ずつカンマで区切る (commify) https://cl.pocari.org/2012-07-12-1.html var commify = function(s) { return s.toString() .split('').reverse().join('') .replace(/(\d\d\d)(?=\d)(?!\d*\.)/g, '$1,') .split('').reverse().join('');};- refs.: Perl クックブック (レシピ 2.16) [4873110378] SUNAOKA Norifumi 2012-07-12T23:59:59+09:00

var commify = function(s) {
    return s.toString()
            .split('').reverse().join('')
            .replace(/(\d\d\d)(?=\d)(?!\d*\.)/g, '$1,')
            .split('').reverse().join('');
};


- refs.: Perl クックブック (レシピ 2.16)
  4873110378
]]> さくらの VPS (CentOS 6.2) にコマンドライン版 Dropbox をインストールする https://cl.pocari.org/2012-04-05-1.html Python 2.6 が必要です。CentOS 5.x は Python 2.4系なので、別途 2.6 系をインストールする必要があります。 リニューアルしたさくらの VPS は、CentOS 6.2 なので、Python 2.6 がインストールされています。 なお、Dropbox は特に GUI は不要なので、CUI (CLI) 版のみインストールします。Dropbox CLI をダウンロードします。$ wget https://www.dropbox.com/download?dl=packages/dropbox.pyまずはインストールします。$HOME/.dropbox-dist にバイナリがダウンロードされます。$ dropbox.py start --installStarting Dropbox...Dropbox is the easiest way to share and store your files online. Want to learn more? Head to http://www.dropbox.com/In order to use Dropbox, you must download the proprietary daemon. [y/n] yDownloading Dropbox... 100%Unpacking Dropbox... 100%Dropbox isn't running!まずは、一回起動します。$ dropbox.py startTo link this computer to a dropbox account, visit the following url:https://www.dropbox.com/cli_link?host_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;cl ... 表示されたリンクへアクセスして、Dropbox アカウントにリンクします。 [Dropbox]次に一回停止して、$ dropbox.py stopDropbox daemon stopped.起動します。$ dropbox.py startStarting Dropbox...Done! わずかこれだけです。sync すれば、普通に $HOME/Dropbox が使えるようになります。 なお、デフォルトでは run sync が有効になっていて、 17500/udp でのブロードキャストが行われてうるさいので、 無効にする方がいいでしょう。無効にしたあとは、Dropbox の再起動をお忘れなく。$ dropbox.py lansync n SUNAOKA Norifumi 2012-04-05T23:59:59+09:00   リニューアルしたさくらの VPS は、CentOS 6.2 なので、Python 2.6 がインストールされています。

  なお、Dropbox は特に GUI は不要なので、CUI (CLI) 版のみインストールします。

  • Dropbox CLI をダウンロードします。

$ wget https://www.dropbox.com/download?dl=packages/dropbox.py

  • まずはインストールします。$HOME/.dropbox-dist にバイナリがダウンロードされます。

$ dropbox.py start --install
Starting Dropbox...
Dropbox is the easiest way to share and store your files online. Want to learn more? Head to http://www.dropbox.com/

In order to use Dropbox, you must download the proprietary daemon. [y/n] y
Downloading Dropbox... 100%
Unpacking Dropbox... 100%
Dropbox isn't running!

  • まずは、一回起動します。

$ dropbox.py start
To link this computer to a dropbox account, visit the following url:
https://www.dropbox.com/cli_link?host_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&cl ...

  表示されたリンクへアクセスして、Dropbox アカウントにリンクします。

  Dropbox

  • 次に一回停止して、

$ dropbox.py stop
Dropbox daemon stopped.

  • 起動します。

$ dropbox.py start
Starting Dropbox...Done!

  わずかこれだけです。sync すれば、普通に $HOME/Dropbox が使えるようになります。

  なお、デフォルトでは run sync が有効になっていて、 17500/udp でのブロードキャストが行われてうるさいので、
  無効にする方がいいでしょう。無効にしたあとは、Dropbox の再起動をお忘れなく。

$ dropbox.py lansync n

]]> ワイルドカードの SSL 自己署名証明書の作成 https://cl.pocari.org/2012-02-22-1.html 名前ベースのバーチャルホストの検証のために、ワイルドカードなオレオレ証明書を作成。 なんてことはない、普通のオレオレ証明書の作り方とおなじ。秘密鍵の作成$ openssl genrsa -out server.key 2048Generating RSA private key, 2048 bit long modulus.....+++..............+++e is 65537 (0x10001)CSR の作成$ openssl req -new -key server.key -out server.csrYou are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [GB]:GBState or Province Name (full name) [Berkshire]:BerkshireLocality Name (eg, city) [Newbury]:NewburyOrganization Name (eg, company) [My Company Ltd]:My Company LtdOrganizational Unit Name (eg, section) []:sectionCommon Name (eg, your name or your server's hostname) []:*.example.comEmail Address []:Please enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []:証明書作成 (10年)$ openssl x509 -days 3653 -in server.csr -out server.crt -req -signkey server.keySignature oksubject=/C=GB/ST=Berkshire/L=Newbury/O=My Company Ltd/OU=section/CN=*.example.comGetting Private key この証明書を使って、特に問題なく、名前ベースのバーチャルホストができた。 SUNAOKA Norifumi 2012-02-22T23:59:59+09:00   なんてことはない、普通のオレオレ証明書の作り方とおなじ。

  • 秘密鍵の作成

$ openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.....+++
..............+++
e is 65537 (0x10001)

  • CSR の作成

$ openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:GB
State or Province Name (full name) [Berkshire]:Berkshire
Locality Name (eg, city) [Newbury]:Newbury
Organization Name (eg, company) [My Company Ltd]:My Company Ltd
Organizational Unit Name (eg, section) []:section
Common Name (eg, your name or your server's hostname) []:*.example.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

  • 証明書作成 (10年)

$ openssl x509 -days 3653 -in server.csr -out server.crt -req -signkey server.key
Signature ok
subject=/C=GB/ST=Berkshire/L=Newbury/O=My Company Ltd/OU=section/CN=*.example.com
Getting Private key

  この証明書を使って、特に問題なく、名前ベースのバーチャルホストができた。
]]> さくらの VPS (CentOS) の Postfix で DKIM 対応にする https://cl.pocari.org/2011-10-26-1.html $ sudo yum install --enablerepo=epel dkim-milter$ dkim-genkey -r -d pocari.org$ sudo mkdir /etc/mail/dkim-milter/keys/pocari.org$ sudo mv default.private /etc/mail/dkim-milter/keys/pocari.org/default$ sudo mv default.txt /etc/mail/dkim-milter/keys/pocari.org$ sudo chown -R dkim-milter:dkim-milter /e... SUNAOKA Norifumi 2011-10-26T23:59:59+09:00

$ sudo yum install --enablerepo=epel dkim-milter
$ dkim-genkey -r -d pocari.org
$ sudo mkdir /etc/mail/dkim-milter/keys/pocari.org
$ sudo mv default.private /etc/mail/dkim-milter/keys/pocari.org/default
$ sudo mv default.txt /etc/mail/dkim-milter/keys/pocari.org
$ sudo chown -R dkim-milter:dkim-milter /etc/mail/dkim-milter/keys/pocari.org

  /etc/mail/dkim-milter/keys/pocari.org/default.txt を zone ファイルに登録。

$ dig default._domainkey.pocari.org TXT

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> default._domainkey.pocari.org TXT
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18053
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;default._domainkey.pocari.org. IN      TXT

;; ANSWER SECTION:
default._domainkey.pocari.org. 300 IN   TXT     "v=DKIM1\; g=*\; k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUWmQHRIpLQ3OO6RUt7QSguR4tuWZzm6mBRB3e1Q+irkdZ5MgARUx27dU31oHVVcyUZquYztnuunnRpOim/VE0YwpJmNSfwxA4lTyQsP6cG9a+qujew6ddljixy+fBGLKyZBT4sKEPoCNFHSlvwLUHrfgiSIHDfdDoBHNgMYl8AQIDAQAB"

;; Query time: 12 msec
;; SERVER: 210.224.163.4#53(210.224.163.4)
;; WHEN: Wed Oct 26 12:42:11 2011
;; MSG SIZE  rcvd: 299

$ diff -u /etc/mail/dkim-milter/dkim-filter.conf.org /etc/mail/dkim-milter/dkim-filter.conf
$ sudo vim /etc/mail/dkim-milter/keys/keylist

- refs.: HOWTO Setup dkim-milter with postfix under CentOS 5
  http://wiki.cementhorizon.com/display/CH/HOWTO+Setup+dkim-milter+with+post ...
]]> Munin でインストールしたプラグインの情報が取得できない https://cl.pocari.org/2011-10-06-1.html あるサーバに Munin で nginx を監視するために nginx のプラグインをインストールしましたが、 なぜだか、情報が取得できない現象に出くわしました。 具体的には、Munin のレポートページに表示されません。 1. nginx_status をダウンロードして、/usr/share/munin/plugins/nginx_status へコピー。 2. /etc/munin/plugins にシンボリックリンクを張る。 これだけでいいかと思ったのですが、ダメでした。 原因を探るために perl /etc/munin/plugins/nginx_status を実行してみても、特に問題なく結果が出力されます。 色々調べていると、munin-run なるコマンドの存在が…! $ /usr/sbin/munin-run nginx_statusERROR: Could not execute plugin (plugin doesn't exist?). あれ?実行されません。パーミッションを見てみると、 0644 (rw-r--r--) で実行権限がありません。 これが原因かと思い、sudo chmod 0755 /usr/share/munin/plugins/nginx_status したあとに、再度 nginx_status を。 $ /usr/sbin/munin-run nginx_statustotal.value 2reading.value 0wr:uuuuuuuiting.value 1waiting.value 1 なるほど。これでいけるのか。その後、munin-node を再起動 (sudo /etc/init.d/munin-node restart) して無事、レポートに表示されるようになりました。 要は、 1. プラグインをインストールしたら、実行権限をつけること。 2. プラグインの動作確認は、munin-run で。 ってことでした。 - refs.: Debugging Munin plugins http://munin-monitoring.org/wiki/Debugging_Munin_plugins SUNAOKA Norifumi 2011-10-06T23:59:59+09:00   なぜだか、情報が取得できない現象に出くわしました。
  具体的には、Munin のレポートページに表示されません。

  1. nginx_status をダウンロードして、/usr/share/munin/plugins/nginx_status へコピー。
  2. /etc/munin/plugins にシンボリックリンクを張る。

  これだけでいいかと思ったのですが、ダメでした。
  
  原因を探るために perl /etc/munin/plugins/nginx_status を実行してみても、特に問題なく結果が出力されます。
  色々調べていると、munin-run なるコマンドの存在が…!
  

$ /usr/sbin/munin-run nginx_status
ERROR: Could not execute plugin (plugin doesn't exist?).

  あれ?実行されません。パーミッションを見てみると、 0644 (rw-r--r--) で実行権限がありません。
  これが原因かと思い、sudo chmod 0755 /usr/share/munin/plugins/nginx_status したあとに、再度 nginx_status を。
  

$ /usr/sbin/munin-run nginx_status
total.value 2
reading.value 0
wr:uuuuuuuiting.value 1
waiting.value 1

  なるほど。これでいけるのか。その後、munin-node を再起動 (sudo /etc/init.d/munin-node restart) して無事、レポートに表示されるようになりました。
  
  要は、
  
  1. プラグインをインストールしたら、実行権限をつけること。
  2. プラグインの動作確認は、munin-run で。

  ってことでした。
  
- refs.: Debugging Munin plugins
  http://munin-monitoring.org/wiki/Debugging_Munin_plugins
]]> svn diff で改行コードを無視する https://cl.pocari.org/2011-08-18-1.html svn diff で改行コードを無視する場合は、-x --ignore-eol-style を指定する。$ svn diff -x --ignore-eol-style SUNAOKA Norifumi 2011-08-18T23:59:59+09:00

$ svn diff -x --ignore-eol-style

]]> mod_rpaf の RPAFproxy_ips に 192.0.2. とか書きたい https://cl.pocari.org/2011-08-04-1.html リバースプロキシ環境下で、リモートホストのIPアドレスを取得するために、 mod_rpaf を使っていますが、RPAFproxy_ips は 192.0.2.0 のように、IPアドレス を指定する必要があり、192.0.2. のようにはかけません。 つまり、RPAFproxy_ip に 192.0.2. のように指定したい話。 設定では無理そうなので、mod_rpaf-2.0.c を書き換えました。--- mod_rpaf-2.0.c.orig 2008-01-01 12:05:40.000000000 +0900+++ mod_rpaf-2.0.c 2011-08-04 12:02:13.000000000 +0900@@ -139,7 +139,7 @@ int i; char **list = (char**)proxy_ips-&gt;elts; for (i = 0; i < proxy_ips-&gt;nelts; i++) {- if (strcmp(remote_ip, list[i]) == 0)+ if (strncmp(remote_ip, list[i], strlen(list[i])) == 0) return 1; } return 0; これで、下記のように書けます。RPAFenable OnRPAFsethostname OffRPAFproxy_ips 192.0.2.- refs: mod_rpaf for Apache http://stderr.net/apache/rpaf/ SUNAOKA Norifumi 2011-08-04T23:59:59+09:00   mod_rpaf を使っていますが、RPAFproxy_ips は 192.0.2.0 のように、IPアドレス
  を指定する必要があり、192.0.2. のようにはかけません。

  つまり、RPAFproxy_ip に 192.0.2. のように指定したい話。

  設定では無理そうなので、mod_rpaf-2.0.c を書き換えました。

--- mod_rpaf-2.0.c.orig 2008-01-01 12:05:40.000000000 +0900
+++ mod_rpaf-2.0.c      2011-08-04 12:02:13.000000000 +0900
@@ -139,7 +139,7 @@
     int i;
     char **list = (char**)proxy_ips->elts;
     for (i = 0; i < proxy_ips->nelts; i++) {
-        if (strcmp(remote_ip, list[i]) == 0)
+        if (strncmp(remote_ip, list[i], strlen(list[i])) == 0)
             return 1;
     }
     return 0;


  これで、下記のように書けます。

RPAFenable On
RPAFsethostname Off
RPAFproxy_ips 192.0.2.


- refs: mod_rpaf for Apache
  http://stderr.net/apache/rpaf/
]]> Windows 7 でファイル名に ~ (チルダ)を含むファイルを検索する https://cl.pocari.org/2011-06-23-1.html [チルダを検索] 検索窓に名前:~="~" を入力。同様に、「$」を含むものを検索する場合は、名前:~="$" で検索。 SUNAOKA Norifumi 2011-06-23T23:59:59+09:00

  検索窓に

名前:~="~"

  を入力。同様に、「$」を含むものを検索する場合は、

名前:~="$"

  で検索。
]]> Zend_Oauth_Consumer でプロキシサーバを経由する方法 https://cl.pocari.org/2011-06-07-2.html $config = array( 'siteUrl' =&gt; 'http://example.com/oauth', 'consumerKey' =&gt; 'xxxxx', 'consumerSecret' =&gt; 'xxxxx', 'callbackUrl' =&gt; 'http://example.com/callback', 'authorizeUrl' =&gt; 'https://example.com/oauth/authorize',);$client = new Zend_Http_Client(null, array( 'a... Norifumi Sunaoka 2011-06-07T23:59:59+09:00

$config = array(
    'siteUrl'        => 'http://example.com/oauth',
    'consumerKey'    => 'xxxxx',
    'consumerSecret' => 'xxxxx',
    'callbackUrl'    => 'http://example.com/callback',
    'authorizeUrl'   => 'https://example.com/oauth/authorize',
);

$client = new Zend_Http_Client(null, array(
    'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
    'proxy_host' => 'proxyサーバのホスト名',
    'proxy_port' => proxyサーバのポート番号,
));

$consumer = new Zend_Oauth_Consumer($config);
$consumer->setHttpClient($client);

]]> Zend_Service_Twitter でプロキシサーバを経由する方法 https://cl.pocari.org/2011-06-07-1.html $client = new Zend_Http_Client(null, array( 'adapter' =&gt; 'Zend_Http_Client_Adapter_Proxy', 'proxy_host' =&gt; 'proxyサーバのホスト名', 'proxy_port' =&gt; proxyサーバのポート番号,));$twitter = new Zend_Service_Twitter(array( 'accessToken' =&gt; $access_token, // Zend_Oauth_Token_Access));$twitter-&gt;setLocalHttpClient($client); Norifumi Sunaoka 2011-06-07T23:59:59+09:00

$client = new Zend_Http_Client(null, array(
    'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
    'proxy_host' => 'proxyサーバのホスト名',
    'proxy_port' => proxyサーバのポート番号,
));

$twitter = new Zend_Service_Twitter(array(
    'accessToken' => $access_token, // Zend_Oauth_Token_Access
));
$twitter->setLocalHttpClient($client);

]]> CSR、証明書、秘密鍵等の情報を取得 https://cl.pocari.org/2011-02-02-1.html - 秘密鍵の内容を確認$ openssl rsa -in server.key -text- CSRの内容を確認$ openssl req -in server.csr -text- 証明書の内容を確認$ openssl x509 -in server.cer -text- CRLの内容を確認$ openssl crl -in server.crl -text Norifumi Sunaoka 2011-02-02T23:59:59+09:00 - 秘密鍵の内容を確認

$ openssl rsa -in server.key -text

- CSRの内容を確認

$ openssl req -in server.csr -text

- 証明書の内容を確認

$ openssl x509 -in server.cer -text

- CRLの内容を確認

$ openssl crl -in server.crl -text

]]> Amazon Web Services (AWS) の Access Keys の取得 https://cl.pocari.org/2010-05-15-1.html サイトが変わってワケがわからなくなったのでメモ。- Amazon Web Services - Security Credentials http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=ac ... にアクセスするか、下記 Amazon Web Services から、- Amazon Web Services http://aws.amazon.com/ Account - Security Credentials を辿る。 Norifumi Sunaoka 2010-05-15T23:59:59+09:00
- Amazon Web Services - Security Credentials
  http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=ac ...

  にアクセスするか、下記 Amazon Web Services から、

- Amazon Web Services
  http://aws.amazon.com/

  Account - Security Credentials を辿る。
]]>
PostgreSQL の初期設定 https://cl.pocari.org/2010-04-22-1.html 1. CentOS 付属の PostgreSQL は、8.1.11 のため 8.4.x をインストールする 下記サイトより、pgdg-centos-8.4-x.noarch をダウンロードし、yum による管理を行う。- pgdg-centos - PostgreSQL 9.0.X PGDG RPMs for CentOS - Yum Repository Configuration http://yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html$ sudo rpm -ivh pgdg-centos-8.4-x.noarch.rpm$ sudo yum check-update$ sudo yum install postgresql-server2. DB の初期化、PostgreSQL の起動を行う$ sudo service postgresql initdb -E UTF8 --no-locale$ sudo chkconfig postgresql on$ sudo service postgresql start3. ユーザの追加 username というユーザを追加する場合$ sudo -u postgres createuser -P usernameEnter password for new role: <パスワード&gt;Enter it again: <パスワード&gt;Shall the new role be a superuser? (y/n) nShall the new role be allowed to create databases? (y/n) nShall the new role be allowed to create more new roles? (y/n) n4. DB の作成 dbname という DB を、username オーナーで作る場合。$ sudo -u postgres createdb -E UTF-8 -O username dbname5. 他のサーバからの接続を許可する$ sudo vi /var/lib/pgsql/data/postgresql.conf 他のサーバ全てからの接続を許可する場合listen_addresses = '*' いくつかのサーバを指定する場合(「,」でつなぐ)listen_addresses = 'localhost,192.0.2.1'$ sudo vi /var/lib/pgsql/data/pg_hba.conf 下記を追加し、パスワード認証で接続を許可する。host all all 192.0.2.1/32 md5 Norifumi Sunaoka 2010-04-22T23:59:59+09:00

1. CentOS 付属の PostgreSQL は、8.1.11 のため 8.4.x をインストールする


  下記サイトより、pgdg-centos-8.4-x.noarch をダウンロードし、yum による管理を行う。

- pgdg-centos - PostgreSQL 9.0.X PGDG RPMs for CentOS - Yum Repository Configuration
  http://yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html

$ sudo rpm -ivh pgdg-centos-8.4-x.noarch.rpm
$ sudo yum check-update
$ sudo yum install postgresql-server

2. DB の初期化、PostgreSQL の起動を行う

$ sudo service postgresql initdb -E UTF8 --no-locale
$ sudo chkconfig postgresql on
$ sudo service postgresql start

3. ユーザの追加


  username というユーザを追加する場合

$ sudo -u postgres createuser -P username
Enter password for new role: <パスワード>
Enter it again: <パスワード>
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

4. DB の作成


  dbname という DB を、username オーナーで作る場合。

$ sudo -u postgres createdb -E UTF-8 -O username dbname

5. 他のサーバからの接続を許可する

$ sudo vi /var/lib/pgsql/data/postgresql.conf

  他のサーバ全てからの接続を許可する場合

listen_addresses = '*'


  いくつかのサーバを指定する場合(「,」でつなぐ)

listen_addresses = 'localhost,192.0.2.1'

$ sudo vi /var/lib/pgsql/data/pg_hba.conf

  下記を追加し、パスワード認証で接続を許可する。

host    all         all         192.0.2.1/32         md5

]]> Subversion 1.6 で zsh の補完が失敗する https://cl.pocari.org/2010-01-06-1.html $ cd /usr/share/zsh/site-functions$ sudo wget -c http://gvn.googlecode.com/svn/trunk/contrib/zsh/_subversion- ref.: Re: Subversion 1.5 and ZSH Completion http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&amp;dsMessageId= ... Norifumi Sunaoka 2010-01-06T23:59:59+09:00

$ cd /usr/share/zsh/site-functions
$ sudo wget -c http://gvn.googlecode.com/svn/trunk/contrib/zsh/_subversion

- ref.: Re: Subversion 1.5 and ZSH Completion
  http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId= ...
]]> trac で Shift-JIS が文字化けしないようにする https://cl.pocari.org/2009-12-16-1.html trac.ini の default_charset を japanese.ms932 に設定する。 python-japanese-codecs が必要[trac]default_charset = japanese.ms932- ref.: JapaneseCodecs http://www.python.jp/Zope/download/JapaneseCodecs Norifumi Sunaoka 2009-12-16T23:59:59+09:00   python-japanese-codecs が必要

[trac]
default_charset = japanese.ms932


- ref.: JapaneseCodecs
  http://www.python.jp/Zope/download/JapaneseCodecs
]]> Vim でバッファにあるファイルの中身を一括置換 https://cl.pocari.org/2009-10-30-1.html :bufdo :%s/foo/bar/g | :w Norifumi Sunaoka 2009-10-30T23:59:59+09:00

:bufdo :%s/foo/bar/g | :w

]]> Zend Studio を使って CLI をデバッグする https://cl.pocari.org/2009-09-26-1.html export QUERY_STRING="start_debug=1&amp;debug_host=192.168.1.2&amp;debug_port=10137&amp;debug_stop=1&amp;no_remote=1&amp;debug_session_id=12345" をサーバに設定して、CLI プログラムを動かす debug_host: Zend Studio が動いている機械のホスト名/IPアドレス debug_port: Zend Studio のポート番号 debug_session_id: 任意 Norifumi Sunaoka 2009-09-26T23:59:59+09:00

export QUERY_STRING="start_debug=1&debug_host=192.168.1.2&debug_port=10137&debug_stop=1&no_remote=1&debug_session_id=12345"

  をサーバに設定して、CLI プログラムを動かす
  debug_host: Zend Studio が動いている機械のホスト名/IPアドレス
  debug_port: Zend Studio のポート番号
  debug_session_id: 任意
]]> PASMO 壊れる https://cl.pocari.org/2009-07-29-1.html オートチャージ付き PASMO 定期券を利用しているのですが、改札を出られなくなり、 窓口に行ったら、「障害再発行整理票」を発行してもらえました。 どうも、IC チップが壊れているとの説明。 聞くところによると、意外とこの障害は多いとのこと。 「障害再発行整理票」を PASMO にセロハンテープで留められ、とりあえずは改札で 見せれば、特に問題なく乗車できるらしい (実際に問題なく通過できました)。 ただ、何かと不便なので、早速再発行してもらいました (再発行できる駅は決まっ ているらしいです。近くだと吉祥寺駅か明大前。)。 窓口に持っていくと、数分で再発行完了。 - ref.: PASMOが使えなくなったとき | 紛失・再発行 | PASMO(パスモ) http://www.pasmo.co.jp/reissue/break.html Norifumi Sunaoka 2009-07-29T23:59:59+09:00   窓口に行ったら、「障害再発行整理票」を発行してもらえました。
  どうも、IC チップが壊れているとの説明。
  聞くところによると、意外とこの障害は多いとのこと。
  
  「障害再発行整理票」を PASMO にセロハンテープで留められ、とりあえずは改札で
  見せれば、特に問題なく乗車できるらしい (実際に問題なく通過できました)。
  
  ただ、何かと不便なので、早速再発行してもらいました (再発行できる駅は決まっ
  ているらしいです。近くだと吉祥寺駅か明大前。)。
  窓口に持っていくと、数分で再発行完了。
  
- ref.: PASMOが使えなくなったとき | 紛失・再発行 | PASMO(パスモ)
  http://www.pasmo.co.jp/reissue/break.html
]]>
Oracle の表領域を表示する SQL https://cl.pocari.org/2009-07-28-2.html SYSDBA でのログインが必要。SQLSELECT T.TABLESPACE_NAME &quot;表領域&quot;, ROUND(T.BYTES / (1024 * 1024), 0) &quot;割当済(MB)&quot;, ROUND((T.BYTES - SUM(F.BYTES)) / (1024 * 1024), 0) &quot;使用量(MB)&quot;, ROUND(SUM(F.BYTES) / (1024 * 1024), 0) &quot;空容量(MB)&quot;, ROUND((1 - SUM(F.BYTES) / T.BYTES) * 100, 2) &quot;使用率(%)&quot;FROM SYS.DBA_FREE_SPACE F, (SELECT TABLESPACE_NAME, SUM(BYTES) BYTES FROM SYS.DBA_DATA_FILES GROUP BY TABLESPACE_NAME ) TWHERE T.TABLESPACE_NAME = F.TABLESPACE_NAME(+)GROUP BY T.TABLESPACE_NAME, T.BYTES/出力表領域 割当済(MB) 使用量(MB) 空容量(MB) 使用率(%)------------------------------ ---------- ---------- ---------- ----------SYSAUX 560 544 16 97.11USERS 2640 1151 1489 43.59SYSTEM 400 361 39 90.17UNDO 500 10 491 1.9- ref.: Oracle Technology Network (OTN) Japan - 掲示板 : 表領域の使用率確認 ... http://otn.oracle.co.jp/forum/message.jspa?messageID=8087948 Norifumi Sunaoka 2009-07-28T23:59:59+09:00

  • SQL

SELECT
    T.TABLESPACE_NAME "表領域",
    ROUND(T.BYTES / (1024 * 1024), 0) "割当済(MB)",
    ROUND((T.BYTES - SUM(F.BYTES)) / (1024 * 1024), 0) "使用量(MB)",
    ROUND(SUM(F.BYTES) / (1024 * 1024), 0) "空容量(MB)",
    ROUND((1 - SUM(F.BYTES) / T.BYTES) * 100, 2) "使用率(%)"
FROM
    SYS.DBA_FREE_SPACE F,
    (SELECT
        TABLESPACE_NAME,
        SUM(BYTES) BYTES
     FROM
        SYS.DBA_DATA_FILES
     GROUP BY
        TABLESPACE_NAME
     ) T
WHERE
    T.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
GROUP BY
    T.TABLESPACE_NAME,
    T.BYTES
/

  • 出力

表領域                         割当済(MB) 使用量(MB) 空容量(MB)  使用率(%)
------------------------------ ---------- ---------- ---------- ----------
SYSAUX                                560        544         16      97.11
USERS                                2640       1151       1489      43.59
SYSTEM                                400        361         39      90.17
UNDO                                  500         10        491        1.9


- ref.: Oracle Technology Network (OTN) Japan - 掲示板 : 表領域の使用率確認 ...
  http://otn.oracle.co.jp/forum/message.jspa?messageID=8087948
]]> Oracle の一時表領域を表示する SQL https://cl.pocari.org/2009-07-28-1.html SYSDBA でのログインが必要。SQLSELECT DT.TABLESPACE_NAME &quot;表領域&quot;, ROUND(DT.BYTES / (1024 * 1024), 0) &quot;割当済(MB)&quot;, ROUND(T.BYTES_CACHED / (1024 * 1024), 0) &quot;空容量(MB)&quot;, ROUND(T.BYTES_CACHED / DT.BYTES * 100, 2) &quot;使用率(%)&quot;FROM SYS.DBA_TEMP_FILES DT, V$TEMP_EXTENT_POOL T, V$TEMPFILE VWHERE T.FILE_ID(+)= DT.FILE_ID AND DT.FILE_ID = V.FILE#/出力表領域 割当済(MB) 空容量(MB) 使用率(%)------------------------------ ---------- ---------- ----------TEMP 528 527 99.81 Norifumi Sunaoka 2009-07-28T23:59:59+09:00

  • SQL

SELECT
    DT.TABLESPACE_NAME "表領域",
    ROUND(DT.BYTES / (1024 * 1024), 0) "割当済(MB)",
    ROUND(T.BYTES_CACHED / (1024 * 1024), 0) "空容量(MB)",
    ROUND(T.BYTES_CACHED / DT.BYTES * 100, 2) "使用率(%)"
FROM
    SYS.DBA_TEMP_FILES DT,
    V$TEMP_EXTENT_POOL T,
    V$TEMPFILE V
WHERE
    T.FILE_ID(+)= DT.FILE_ID AND
    DT.FILE_ID = V.FILE#
/

  • 出力

表領域                         割当済(MB) 空容量(MB)  使用率(%)
------------------------------ ---------- ---------- ----------
TEMP                                  528        527      99.81

]]> PHP の cURL 実際にリクエストされたヘッダを確認する方法 https://cl.pocari.org/2009-02-16-1.html PHP で cURL 拡張モジュールを利用しているときに、デバック用に実際にリクエストしているヘッダの内容を見たいときがあります。 その場合は、以下のように CURLOPT_VERBOSE と CURLOPT_STDERR を使って、ファイルに出力することが出来ます。// 保存するファイル$fp = fopen('/tmp/curl.log', 'a');// 詳細な情報を出力するcurl_setopt($ch, CURLOPT_VERBOSE, true);// STDERR の代わりにエラーを出力するファイルポインタcurl_setopt($ch, CURLOPT_STDERR, $fp); 例として、Google へのアクセスを見てみます。$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/');curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// 保存するファイル$fp = fopen('/tmp/curl.log', 'a');// 詳細な情報を出力するcurl_setopt($ch, CURLOPT_VERBOSE, true);// STDERR の代わりにエラーを出力するファイルポインタcurl_setopt($ch, CURLOPT_STDERR, $fp);$ret = curl_exec($ch);fclose($fp);curl_close($ch); これを実行すると、/tmp/curl.log には以下のように出力されます。* About to connect() to www.google.com port 80 (#0)* Trying 66.249.89.147... * connected* Connected to www.google.com (66.249.89.147) port 80 (#0)&gt; GET / HTTP/1.1Host: www.google.comAccept: */*< HTTP/1.1 302 Found< Location: http://www.google.co.jp/< Cache-Control: private< Content-Type: text/html; charset=UTF-8< Set-Cookie: PREF=ID=c09b07d3b330fa72:TM=1234774504:LM=1234774504:S=Omlx1u3jcFB3egKo; expires=Wed, 16-Feb-2011 08:55:04 GMT; path=/; domain=.google.com< Date: Mon, 16 Feb 2009 08:55:04 GMT< Server: gws< Content-Length: 221* Connection #0 to host www.google.com left intact SUNAOKA Norifumi 2009-02-16T23:59:59+09:00   その場合は、以下のように CURLOPT_VERBOSE と CURLOPT_STDERR を使って、ファイルに出力することが出来ます。

// 保存するファイル
$fp = fopen('/tmp/curl.log', 'a');
// 詳細な情報を出力する
curl_setopt($ch, CURLOPT_VERBOSE, true);
// STDERR の代わりにエラーを出力するファイルポインタ
curl_setopt($ch, CURLOPT_STDERR, $fp);


  例として、Google へのアクセスを見てみます。

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// 保存するファイル
$fp = fopen('/tmp/curl.log', 'a');
// 詳細な情報を出力する
curl_setopt($ch, CURLOPT_VERBOSE, true);
// STDERR の代わりにエラーを出力するファイルポインタ
curl_setopt($ch, CURLOPT_STDERR, $fp);

$ret = curl_exec($ch);

fclose($fp);
curl_close($ch);


  これを実行すると、/tmp/curl.log には以下のように出力されます。

* About to connect() to www.google.com port 80 (#0)
*   Trying 66.249.89.147... * connected
* Connected to www.google.com (66.249.89.147) port 80 (#0)
> GET / HTTP/1.1
Host: www.google.com
Accept: */*

< HTTP/1.1 302 Found
< Location: http://www.google.co.jp/
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Set-Cookie: PREF=ID=c09b07d3b330fa72:TM=1234774504:LM=1234774504:S=Omlx1u3jcFB3egKo; expires=Wed, 16-Feb-2011 08:55:04 GMT; path=/; domain=.google.com
< Date: Mon, 16 Feb 2009 08:55:04 GMT
< Server: gws
< Content-Length: 221
* Connection #0 to host www.google.com left intact

]]> Oracle の LIKE 演算子で _、% を検索文字列として指定する https://cl.pocari.org/2009-01-15-1.html SELECT * FROM foo WHERE bar LIKE '%baz\%' ESCAPE '\';SELECT * FROM foo WHERE bar LIKE '%baz\_' ESCAPE '\'; ESCAPE でエスケープ文字に指定する必要がある (この場合は \ を指定)。 Oracle では、デフォルトのエスケープ文字は決まっていないらしい。 MySQL の場合は、デフォルトのエスケープ文字は、\ になっている。 ただし、MySQL も ESCAPE 節を使えるため、スケープ文字にすることも可能 (この場合は | を指定)。SELECT * FROM foo WHERE bar LIKE '%baz|%' ESCAPE '|';- ref.: 忘れっぽいエンジニアのオラクルSQLリファレンス http://oracle.se-free.com/dml/01_like.html- ref.: MySQL :: MySQL 5.1 リファレンスマニュアル :: 11.3.1 文字列比較関数 http://dev.mysql.com/doc/refman/5.1/ja/string-comparison-functions.html SUNAOKA Norifumi 2009-01-15T23:59:59+09:00

SELECT * FROM foo WHERE bar LIKE '%baz\%' ESCAPE '\';
SELECT * FROM foo WHERE bar LIKE '%baz\_' ESCAPE '\';

  ESCAPE でエスケープ文字に指定する必要がある (この場合は \ を指定)。
  Oracle では、デフォルトのエスケープ文字は決まっていないらしい。
  
  MySQL の場合は、デフォルトのエスケープ文字は、\ になっている。
  ただし、MySQL も ESCAPE 節を使えるため、スケープ文字にすることも可能 (この場合は | を指定)。

SELECT * FROM foo WHERE bar LIKE '%baz|%' ESCAPE '|';

- ref.: 忘れっぽいエンジニアのオラクルSQLリファレンス
  http://oracle.se-free.com/dml/01_like.html

- ref.: MySQL ::   MySQL 5.1 リファレンスマニュアル :: 11.3.1 文字列比較関数
  http://dev.mysql.com/doc/refman/5.1/ja/string-comparison-functions.html
]]> trac で最初に表示されるページを変更する方法 https://cl.pocari.org/2009-01-13-1.html trac では、デフォルトでは最初に表示されるページは、Wiki のページですが、 これを任意のページに変更する方法です。 trac.ini の default_handler のモジュール名を変更すれば任意のページを表示する ことが出来ます。例えば以下は Browse Source (BrowserModule) にする方法です。 [trac]default_handler = BrowserModule 指定できる値と、表示されるページは以下になります。 指定できる値 表示されるページ WikiModule Wiki TimelineModule Timeline RoadmapModule Roadmap BrowserModule Browse Source QueryModule View Tickets (Custom Query) ReportModule View Tickets (Available Reports) NewticketModule New Ticket- ref.: TracIni - The Trac Project http://trac.edgewall.org/wiki/TracIni SUNAOKA Norifumi 2009-01-13T23:59:59+09:00   これを任意のページに変更する方法です。
  
  trac.ini の default_handler のモジュール名を変更すれば任意のページを表示する
  ことが出来ます。例えば以下は Browse Source (BrowserModule) にする方法です。
  

[trac]
default_handler = BrowserModule

  指定できる値と、表示されるページは以下になります。

指定できる値     表示されるページ
WikiModule       Wiki
TimelineModule   Timeline
RoadmapModule    Roadmap
BrowserModule    Browse Source
QueryModule      View Tickets (Custom Query)
ReportModule     View Tickets (Available Reports)
NewticketModule New Ticket


- ref.: TracIni - The Trac Project
  http://trac.edgewall.org/wiki/TracIni
]]> CentOS でファイルの ctime を変更する方法 https://cl.pocari.org/2009-01-07-1.html debugfs の modify_inode を利用して、通常では変更できない ctime を変更する ことが出来ました。 まず、変更したいファイルがあるファイルシステムをアンマウントします。 アンマウントできない場合は、最後に再起動が必要ですが、とりあえずそのまま 続行できました。$ sudo debugfs -w /dev/mapper/VolGroup00-LogVol00debugfs 1.35 (28-Feb-2004)debugfs: cd /mnt/a/tmpdebugfs: stat test.txtInode: 4788224 Type: regular Mode: 0000 Flags: 0x0 Generation: 3112533598User: 48 Group: 48 Size: 7382File ACL: 0 Directory ACL: 0Links: 1 Blockcount: 16Fragment: Address: 0 Number: 0 Size: 0ctime: 0x49643779 -- Wed Jan 7 14:02:49 2009 <- この ctime を変えてみるatime: 0x49618ea8 -- Mon Jan 5 13:38:00 2009mtime: 0x49618ea8 -- Mon Jan 5 13:38:00 2009BLOCKS:(0):9592998, (1):9593000TOTAL: 2debugfs: modify_inode test.txt Mode [0100000] User ID [48] Group ID [48] Size [7382] Creation time [1231304569] 1231130280 <- 変更するには値を入力 Modification time [1231130280] Access time [1231130280] Deletion time [0] Link count [1] Block count [16] File flags [0x0] Generation [0xb9857e5e] File acl [0] High 32bits of size [0] Fragment address [0] Fragment number [0] Fragment size [0] Direct Block #0 [9592998] Direct Block #1 [9593000] Direct Block #2 [0] Direct Block #3 [0] Direct Block #4 [0] Direct Block #5 [0] Direct Block #6 [0] Direct Block #7 [0] Direct Block #8 [0] Direct Block #9 [0] Direct Block #10 [0] Direct Block #11 [0] Indirect Block [0] Double Indirect Block [0] Triple Indirect Block [0]debugfs: stat test.txtInode: 4788224 Type: regular Mode: 0000 Flags: 0x0 Generation: 3112533598User: 48 Group: 48 Size: 7382File ACL: 0 Directory ACL: 0Links: 1 Blockcount: 16Fragment: Address: 0 Number: 0 Size: 0ctime: 0x49618ea8 -- Mon Jan 5 13:38:00 2009 <- この ctime が変わったatime: 0x49618ea8 -- Mon Jan 5 13:38:00 2009mtime: 0x49618ea8 -- Mon Jan 5 13:38:00 2009BLOCKS:(0):9592998, (1):9593000TOTAL: 2debugfs: quit ここで、再度マウントすれば OK。 ただし、アンマウントできなかった場合は、ここでサーバを再起動すれば OK でした。$ ls -lacdrwxrwxrwx 6 sunaoka sunaoka 4.0K Jan 7 14:34 .drwxrwsr-x 3 sunaoka sunaoka 4.0K Jan 7 13:35 ..-rw-r--r-- 1 sunaoka sunaoka 7.3K Jan 5 13:38 test.txt SUNAOKA Norifumi 2009-01-07T23:59:59+09:00   ことが出来ました。
  
  まず、変更したいファイルがあるファイルシステムをアンマウントします。
  アンマウントできない場合は、最後に再起動が必要ですが、とりあえずそのまま
  続行できました。

$ sudo debugfs -w /dev/mapper/VolGroup00-LogVol00
debugfs 1.35 (28-Feb-2004)
debugfs:  cd /mnt/a/tmp
debugfs:  stat test.txt
Inode: 4788224   Type: regular    Mode:  0000   Flags: 0x0   Generation: 3112533598
User:    48   Group:    48   Size: 7382
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 16
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x49643779 -- Wed Jan  7 14:02:49 2009 <- この ctime を変えてみる
atime: 0x49618ea8 -- Mon Jan  5 13:38:00 2009
mtime: 0x49618ea8 -- Mon Jan  5 13:38:00 2009
BLOCKS:
(0):9592998, (1):9593000
TOTAL: 2

debugfs:  modify_inode test.txt
                          Mode    [0100000]
                       User ID    [48]
                      Group ID    [48]
                          Size    [7382]
                 Creation time    [1231304569] 1231130280 <- 変更するには値を入力
             Modification time    [1231130280]
                   Access time    [1231130280]
                 Deletion time    [0]
                    Link count    [1]
                   Block count    [16]
                    File flags    [0x0]
                    Generation    [0xb9857e5e]
                      File acl    [0]
           High 32bits of size    [0]
              Fragment address    [0]
               Fragment number    [0]
                 Fragment size    [0]
               Direct Block #0    [9592998]
               Direct Block #1    [9593000]
               Direct Block #2    [0]
               Direct Block #3    [0]
               Direct Block #4    [0]
               Direct Block #5    [0]
               Direct Block #6    [0]
               Direct Block #7    [0]
               Direct Block #8    [0]
               Direct Block #9    [0]
              Direct Block #10    [0]
              Direct Block #11    [0]
                Indirect Block    [0]
         Double Indirect Block    [0]
         Triple Indirect Block    [0]
debugfs:  stat test.txt
Inode: 4788224   Type: regular    Mode:  0000   Flags: 0x0   Generation: 3112533598
User:    48   Group:    48   Size: 7382
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 16
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x49618ea8 -- Mon Jan  5 13:38:00 2009 <- この ctime が変わった
atime: 0x49618ea8 -- Mon Jan  5 13:38:00 2009
mtime: 0x49618ea8 -- Mon Jan  5 13:38:00 2009
BLOCKS:
(0):9592998, (1):9593000
TOTAL: 2

debugfs:  quit

  ここで、再度マウントすれば OK。
  ただし、アンマウントできなかった場合は、ここでサーバを再起動すれば OK でした。

$ ls -lac
drwxrwxrwx  6 sunaoka sunaoka 4.0K Jan  7 14:34 .
drwxrwsr-x  3 sunaoka sunaoka 4.0K Jan  7 13:35 ..
-rw-r--r--  1 sunaoka sunaoka 7.3K Jan  5 13:38 test.txt

]]> Thunderbird のアドオン Confirm-Address を改造する https://cl.pocari.org/2008-12-25-1.html メールを送信する前にあて先確認ダイアログを表示する Thunderbird アドオンのConfirm-Address ですが、自分の組織のドメインを指定すると、サブドメインも自分の組織のドメイン対象となります。例えば、自分の組織のドメインに、example.com を指定すると、host.example.com も自分の組織として判別されます。この仕様で問題ないと思うのですが、私の場合はサブドメインは別の組織として扱って欲しかったので、改造しました。修正したファイルは、Windows 版なので、%USERPROFILE%\Application Data\Thunderbird\Profiles\<プロファイル&gt;\extensions\confirm-address@kenmaz.net\chrome\content\confirm-address.js--- confirm-address.js.orig 2008-07-31 23:49:02.000000000 +0900+++ confirm-address.js 2008-12-25 13:32:27.000000000 +0900@@ -153,7 +153,7 @@ for(var j = 0; j < domainList.length; j++){ var domainListEntry = domainList[j].toLowerCase();- if(addressLowerCase.indexOf(domainListEntry) != -1){+ if(addressLowerCase.indexOf('@' + domainListEntry) != -1){ yourDomain = true; break; }- Confirm-Address :: Thunderbird Add-ons https://addons.mozilla.org/ja/thunderbird/addon/5582 SUNAOKA Norifumi 2008-12-25T23:59:59+09:00 Confirm-Address ですが、自分の組織のドメインを指定すると、サブドメインも
自分の組織のドメイン対象となります。

例えば、自分の組織のドメインに、example.com を指定すると、host.example.com
も自分の組織として判別されます。

この仕様で問題ないと思うのですが、私の場合はサブドメインは別の組織として扱っ
て欲しかったので、改造しました。

修正したファイルは、Windows 版なので、

%USERPROFILE%\Application Data\Thunderbird\Profiles\<プロファイル>\extensions\confirm-address@kenmaz.net\chrome\content\confirm-address.js

--- confirm-address.js.orig    2008-07-31 23:49:02.000000000 +0900
+++ confirm-address.js    2008-12-25 13:32:27.000000000 +0900
@@ -153,7 +153,7 @@
           
           for(var j = 0; j < domainList.length; j++){
               var domainListEntry = domainList[j].toLowerCase();
-              if(addressLowerCase.indexOf(domainListEntry) != -1){
+              if(addressLowerCase.indexOf('@' + domainListEntry) != -1){
                   yourDomain = true;
                   break;
               }


- Confirm-Address :: Thunderbird Add-ons
  https://addons.mozilla.org/ja/thunderbird/addon/5582
]]> VMware でゲスト OS から外に出られないときの対策 https://cl.pocari.org/2008-12-17-3.html vmnetcfg.exe を使って、NAT の設定をする必要がある。 [Host Virtual Network Mapping] の VMnew8 (実際は NAT を設定しているアダプタ) の NAT の IP アドレスを設定する。 [NAT] の Gateway IP address を上記で設定したサブネットに設定する。 Norifumi Sunaoka 2008-12-17T23:59:59+09:00   [Host Virtual Network Mapping] の VMnew8 (実際は NAT を設定しているアダプタ)
  の NAT の IP アドレスを設定する。
  
  [NAT] の Gateway IP address を上記で設定したサブネットに設定する。
]]>
Zend Studio Toolbar のダウンロード https://cl.pocari.org/2008-12-17-2.html My Zend にログインして、下記ページを開く。 http://www.zend.com/en/products/studio/downloads Studio Browser Toolbars を選択して、ダウンロード Norifumi Sunaoka 2008-12-17T23:59:59+09:00   http://www.zend.com/en/products/studio/downloads
  Studio Browser Toolbars を選択して、ダウンロード
]]>
Zend Studio Web Debugger のアップグレード https://cl.pocari.org/2008-12-17-1.html Zend Studio 6.1.0 にアップグレードしたら、Web Debugger が古いとかいわれた。 My Zend にログインして、下記ページを開く。 http://www.zend.com/en/products/studio/downloads Studio Web Debugger を選択して、ダウンロード (Linux x86 (32 bit) (TAR.GZ) | 2.45 MB | 5.2.14)。 /usr/local/Zend/Platform/lib/Debugger-5.2.14 として展開して、$ mv 4_3_x_comp php-4.3.x$ mv 4_4_x_comp php-4.4.x$ mv 5_0_x_comp php-5.0.x$ mv 5_1_x_comp php-5.1.x$ mv 5_2_x_comp php-5.2.x で、ディレクトリをリネームする。設定 /usr/local/Zend/Core/etc/php.ini を変更するzend_extension_manager.debug_server=/usr/local/Zend/Platform/lib/Debugger-5.2.14確認 Apache を restart して、php -i または phpinfo() で Zend Debugger v5.2.14 になっていれば OK。 Norifumi Sunaoka 2008-12-17T23:59:59+09:00   
  My Zend にログインして、下記ページを開く。
  http://www.zend.com/en/products/studio/downloads
  Studio Web Debugger を選択して、ダウンロード (Linux x86 (32 bit) (TAR.GZ) | 2.45 MB | 5.2.14)。
  
  /usr/local/Zend/Platform/lib/Debugger-5.2.14 として展開して、

$ mv 4_3_x_comp php-4.3.x
$ mv 4_4_x_comp php-4.4.x
$ mv 5_0_x_comp php-5.0.x
$ mv 5_1_x_comp php-5.1.x
$ mv 5_2_x_comp php-5.2.x

  で、ディレクトリをリネームする。

  • 設定

  /usr/local/Zend/Core/etc/php.ini を変更する

zend_extension_manager.debug_server=/usr/local/Zend/Platform/lib/Debugger-5.2.14

  • 確認

  Apache を restart して、php -i または phpinfo() で Zend Debugger v5.2.14 になっていれば OK。
]]> .screenrc をリロードする https://cl.pocari.org/2008-12-11-1.html .screenrc を弄っていて、設定を確認するたびに、quit していましたが、再読み込みすることが出来たらしい。 エスケープ (デフォルトだと C-a) した後に、下記コマンドで OK です。:source $HOME/.screenrc ちなみに、:source ~/.screenrc だと NG でした ($HOME じゃないと駄目)。 SUNAOKA Norifumi 2008-12-11T23:59:59+09:00
  エスケープ (デフォルトだと C-a) した後に、下記コマンドで OK です。

:source $HOME/.screenrc

  ちなみに、:source ~/.screenrc だと NG でした ($HOME じゃないと駄目)。
]]> Subversion で特定のファイルを以前のリビジョンに戻す方法 https://cl.pocari.org/2008-12-09-1.html なんらかの理由で、特定のファイルを以前のリビジョンに戻したいとき。$ svn merge -r 9:6 foo.cU foo.c ちなみに、以下のようにパスを指定して実行するとエラーが出ます。$ svn merge -r 9:6 path/to/foo.csvn: Cannot replace a directory from within (ディレクトリを内側から置換することはできません) この場合は、svn merge する前に該当のディレクトリに移動する必要があります。$ cd path/to$ svn merge -r 9:6 foo.c SUNAOKA Norifumi 2008-12-09T23:59:59+09:00

$ svn merge -r 9:6 foo.c
U foo.c

  ちなみに、以下のようにパスを指定して実行するとエラーが出ます。

$ svn merge -r 9:6 path/to/foo.c
svn: Cannot replace a directory from within (ディレクトリを内側から置換することはできません)

  この場合は、svn merge する前に該当のディレクトリに移動する必要があります。

$ cd path/to
$ svn merge -r 9:6 foo.c

]]> msi を「別のユーザとして実行」する方法 https://cl.pocari.org/2008-06-06-1.html コマンドプロンプトを「別のユーザとして実行」した後に、以下のコマンドC:\&gt; msiexec /i path\to.msi Norifumi Sunaoka 2008-06-06T23:59:59+09:00

C:\> msiexec /i path\to.msi

]]> PuTTY ごった煮版のレジストリから INI ファイルを生成する https://cl.pocari.org/2008-05-10-1.html PuTTY ごった煮版では、設定の保存先をレジストリではなく、INI ファイルにすることが出来ます。 そこでレジストリに保存された設定から INI ファイルを作成するスクリプトを書きました。- putty.iniconv-1.0.0.vbs http://pocari.org/tools/putty/putty.iniconv-1.0.0.vbs 使い方はコマンドプロンプトで以下のようにします。 putty.ini を putty.exe があるフォルダと同じところに置けば完了です。C:\&gt; CScript //Nologo putty.iniconv-1.0.0.vbs &gt; putty.ini'' INI file converter for PuTTY'' Usage:' C:\&gt; CScript //Nologo putty.iniconv-1.0.0.vbs &gt; putty.ini'' Copyright (c) 2008 Norifumi SUNAOKA' <http://cl.pocari.org/2008-05-10-1.html&gt;'' Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)''' Version: 1.0.0'Const HKEY_CURRENT_USER = &amp;H80000001Const PUTTY_SESSIONS_KEY = &quot;Software\SimonTatham\PuTTY\Sessions\&quot;Const PUTTY_HOSTKEYS_KEY = &quot;Software\SimonTatham\PuTTY\SshHostKeys\&quot;Set StdOut = WScript.StdOutSet WMI = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.&quot; &amp; _ &quot;\root\default:StdRegProv&quot;)Set WS = WScript.CreateObject(&quot;Wscript.Shell&quot;)' UseIniFileStdOut.WriteLine &quot;[Generic]&quot; &amp; vbCrLf &amp; &quot;UseIniFile=1&quot; &amp; vbCrLf' SessionsWMI.EnumKey HKEY_CURRENT_USER, PUTTY_SESSIONS_KEY, subkeysFor Each subkey In subkeys StdOut.WriteLine &quot;[Session:&quot; &amp; subkey &amp; &quot;]&quot; Call OutputValues(PUTTY_SESSIONS_KEY &amp; subkey &amp; &quot;\&quot;)Next' SshHostKeysStdOut.WriteLine &quot;[SshHostKeys]&quot;Call OutputValues(PUTTY_HOSTKEYS_KEY)Set WS = NothingSet WMI = NothingSet StdOut = Nothing'' OutputValues'Sub OutputValues(subkey) Set RE = new RegExp RE.pattern = &quot;^\-?[0-9]+$&quot; WMI.EnumValues HKEY_CURRENT_USER, subkey, names, types For i = 0 To UBound(names) value = WS.RegRead(&quot;HKCU\&quot; &amp; subkey &amp; names(i)) If Not RE.Test(value) then value = &quot;&quot;&quot;&quot; &amp; value &amp; &quot;&quot;&quot;&quot; End If StdOut.WriteLine names(i) &amp; &quot;=&quot; &amp; value Next StdOut.WriteLine Set RE = NothingEnd Sub また、以下のサイトで、Perl 版が公開されているのですが、なぜだかうちの環境ではうまくいきませんでした。- ゑBLOG: PuTTYごった煮版 レジストリ<-&gt;INIファイルコンバータ http://yebisuya.dip.jp/yeblog/archives/a000456.html SUNAOKA Norifumi 2008-05-10T23:59:59+09:00   そこでレジストリに保存された設定から INI ファイルを作成するスクリプトを書きました。

- putty.iniconv-1.0.0.vbs
  http://pocari.org/tools/putty/putty.iniconv-1.0.0.vbs

  使い方はコマンドプロンプトで以下のようにします。
  putty.ini を putty.exe があるフォルダと同じところに置けば完了です。

C:\> CScript //Nologo putty.iniconv-1.0.0.vbs > putty.ini

'
' INI file converter for PuTTY
'
' Usage:
' C:\> CScript //Nologo putty.iniconv-1.0.0.vbs > putty.ini
'
' Copyright (c) 2008 Norifumi SUNAOKA
' <http://cl.pocari.org/2008-05-10-1.html>
'
' Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
'
'
' Version: 1.0.0
'

Const HKEY_CURRENT_USER  = &H80000001
Const PUTTY_SESSIONS_KEY = "Software\SimonTatham\PuTTY\Sessions\"
Const PUTTY_HOSTKEYS_KEY = "Software\SimonTatham\PuTTY\SshHostKeys\"

Set StdOut = WScript.StdOut
Set WMI    = GetObject("winmgmts:{impersonationLevel=impersonate}!\\." & _
                       "\root\default:StdRegProv")
Set WS     = WScript.CreateObject("Wscript.Shell")

' UseIniFile
StdOut.WriteLine "[Generic]" & vbCrLf & "UseIniFile=1" & vbCrLf

' Sessions
WMI.EnumKey HKEY_CURRENT_USER, PUTTY_SESSIONS_KEY, subkeys
For Each subkey In subkeys
    StdOut.WriteLine "[Session:" & subkey & "]"
    Call OutputValues(PUTTY_SESSIONS_KEY & subkey & "\")
Next

' SshHostKeys
StdOut.WriteLine "[SshHostKeys]"
Call OutputValues(PUTTY_HOSTKEYS_KEY)

Set WS     = Nothing
Set WMI    = Nothing
Set StdOut = Nothing

'
' OutputValues
'
Sub OutputValues(subkey)
    Set RE = new RegExp
    RE.pattern = "^\-?[0-9]+$"
    
    WMI.EnumValues HKEY_CURRENT_USER, subkey, names, types
    For i = 0 To UBound(names)
        value = WS.RegRead("HKCU\" & subkey & names(i))
        If Not RE.Test(value) then
            value = """" & value & """"
        End If
        StdOut.WriteLine names(i) & "=" & value
    Next
    StdOut.WriteLine
    
    Set RE = Nothing
End Sub


  また、以下のサイトで、Perl 版が公開されているのですが、なぜだかうちの環境ではうまくいきませんでした。

- ゑBLOG: PuTTYごった煮版 レジストリ<->INIファイルコンバータ
  http://yebisuya.dip.jp/yeblog/archives/a000456.html
]]>