2008年8月2日土曜日

[ruby] rubygems でmysql ライブラリをインストールする

mysql-develが入っているか確認する

$ rpm -qa | grep -i mysql
mysql-5.0.45-7.el5
mysql-devel-5.0.45-7.el5

gemでインストールします(そのままだとエラーが出ますね)

$ sudo /opt/ruby/bin/gem install mysql --no-rdoc --no-ri
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/opt/ruby/bin/ruby extconf.rb install mysql --no-rdoc --no-ri
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/ruby/bin/ruby
--with-mysql-config
--without-mysql-config
(snip)

Gem files will remain installed in /opt/ruby/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/ruby/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

mysqlの設定を、mysql-configから取得するように指定

$ sudo /opt/ruby/bin/gem install mysql --no-rdoc --no-ri -- --with-mysql-config
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed

チェックする(require でmysqlが読み込めればOK)

$ /opt/ruby/bin/irb -rrubygems
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> exit

成功したっぽい

2008年7月28日月曜日

[unix] スペースを含むファイル名をfindとxargsで使う方法

Mac OS Xみたいに、ディレクトリやファイル名にスペースを含んでいる場合
find と xargsをそのまま実行すると
スペースの前後で別々の引数として処理される(´・ω・`)

・対応方法
スペースを区切り文字にするのではなく0(ゼロ、null)を区切り文字にする。

$ find . -type f -print0 | xargs -0 ls
のように
find には、-print0
xargsには、-0もしくは--null
オプションを指定する。

それでも正しく認識せんぞという場合は効率が悪いけど
xargs -i と "{}" を書くようにしよう・・・
 find -print0 | xargs --null -i ls "{}"

2008年7月24日木曜日

[bash][小ネタ] read でいろいろ

$ read -ep 'USERNAME: ' uname
$ echo $uname


-e で、readlineの機能(スクロールバックやCtrl-rでヒストリ検索など)を利用できる。
-p で、プロンプトを表示できます。

2008年7月16日水曜日

[nkf] nkfのインストール

ソースからnkfを入れる

http://sourceforge.jp/projects/nkf/ からダウンロード
$ wget http://iij.dl.sourceforge.jp/nkf/26243/nkf-2.0.8b.tar.gz


$ tar xvfz nkf-2.0.8b.tar.gz
$ cd nkf-2.0.8


Makefileを修正
$ vi Makefile


修正内容
$ diff -dc Makefile.bak Makefile

*** Makefile.bak 2008-07-16 20:59:16.000000000 +0900
--- Makefile 2008-07-16 21:02:19.000000000 +0900
***************
*** 1,5 ****
! CC = cc
! CFLAGS = -O
# CFLAGS = -O3
SHAR = shar
# SHAR = shar -T
--- 1,5 ----
! CC = gcc
! CFLAGS = -O3 -Wall
# CFLAGS = -O3
SHAR = shar
# SHAR = shar -T

デフォルト出力をutf8にする場合config.hファイルを修正
$ vi config.h


config.h 修正内容
$ diff -dc config.h.bak config.h

*** config.h.bak 2007-07-25 00:13:03.000000000 +0900
--- config.h 2008-07-16 20:58:10.000000000 +0900
***************
*** 59,68 ****
/******************************/
/* デフォルトの出力コード選択 */
/* Select DEFAULT_CODE */
! #define DEFAULT_CODE_JIS
/* #define DEFAULT_CODE_SJIS */
/* #define DEFAULT_CODE_EUC */
! /* #define DEFAULT_CODE_UTF8 */
/******************************/
#else
#define DEFAULT_CODE_SJIS
--- 59,68 ----
/******************************/
/* デフォルトの出力コード選択 */
/* Select DEFAULT_CODE */
! /* #define DEFAULT_CODE_JIS */
/* #define DEFAULT_CODE_SJIS */
/* #define DEFAULT_CODE_EUC */
! #define DEFAULT_CODE_UTF8
/******************************/
#else
#define DEFAULT_CODE_SJIS

make
$ make

インストールは、パスの通っているディレクトリにコピー
$ sudo cp -p nkf /usr/local/bin/

2008年6月21日土曜日

[OpenBSD] pkg_add パッケージの設定

ring serverを使うのが良いですね。
$ vi .bashrc
# PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/
# PKG_PATH=http://ring.k-opti.com/archives/OpenBSD/`uname -r`/packages/`uname -m`/
PKG_PATH=http://www.dnsbalance.ring.gr.jp/archives/OpenBSD/`uname -r`/packages/`uname -m`/
export PKG_PATH