<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>b.l0g.jp</title>
	<atom:link href="http://b.l0g.jp/feed/" rel="self" type="application/rss+xml" />
	<link>http://b.l0g.jp</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 11:07:36 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/feed/" />
		<item>
		<title>MySQL ユーザのホストをワイルドカードで指定してもlocalhostは含まれない</title>
		<link>http://b.l0g.jp/mysql/user-at-localhost/</link>
		<comments>http://b.l0g.jp/mysql/user-at-localhost/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 11:07:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=935</guid>
		<description><![CDATA[MySQLをインストールしたので、とりあえずワイルドカードでホスト名を指定してテスト用のユーザを作成。 mysql&#62; show databases; +--------------------+ &#124; Databas [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLをインストールしたので、とりあえずワイルドカードでホスト名を指定してテスト用のユーザを作成。</p>
<pre>

mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hoge               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql&gt; grant select on hoge.* to testuser@'%' identified by 'password';
Query OK, 0 rows affected (0.07 sec)

mysql&gt; select host,user from mysql.user;
+-----------+----------+
| host      | user     |
+-----------+----------+
| %         | testuser |
| 127.0.0.1 | root     |
| localhost |          |
| localhost | root     |
+-----------+----------+
7 rows in set (0.00 sec)

mysql&gt; quit
</pre>
<p>この状態で、MySQLがインストールされているサーバ自体からそのままtestuserでログインしようとすると、アクセスが拒否される。</p>
<pre>

testserver$ mysql -utestuser -p
Enter password:
ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: YES)
</pre>
<p>しかし、他のサーバからアクセスしてみると、接続は成功して、hogeデータベースへのアクセスもできる。</p>
<pre>

anotherserver$ mysql -utestuser -p -h testserver hoge
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hoge               |
| test               |
+--------------------+
3 rows in set (0.00 sec)
</pre>
<p>「testuser@&#8217;%'」の「%」はワイルドカードなので、localhostも含めた全てのホストを指すものかと思ったら、どうやらそれは間違いのようだ。</p>
<p>調べてみたところ、以下のような仕組み。</p>
<p>4.8.2 MySQL への新規ユーザの追加<br />
<a href="http://dev.mysql.com/doc/refman/5.1/ja/adding-users.html" target="_blank"> http://dev.mysql.com/doc/refman/5.1/ja/adding-users.html</a></p>
<blockquote><p>monty というユーザ名と some_pass というパスワードのアカウントが 2つ存在します。どちらもフル権限を持つスーパーユーザのアカウントです。&#8217;monty&#8217;@'localhost&#8217;) というアカウントは、ローカル ホストから接続するときにだけ使用できます。一方の &#8216;monty&#8217;@'%&#8217; というアカウントは、どのホストからでも接続できます。注意： monty というアカウントは両方とも、monty としてどこからでも接続できる必要があります。この localhost でアカウントを持っていない場合、monty でローカル ホストから接続したときに、mysql_install_db で作成している localhost のエントリで、匿名ユーザのアカウントとして優先になります。つまり、 monty が匿名ユーザとして扱われます。この理由は、&#8217;monty&#8217;@'%&#8217; よりも、匿名ユーザの方が具体的な Host カラム値にあるため、匿名の方が、user テーブルのソート順で先にきます。. (user テーブルのソートに関しては、項4.7.5. 「アクセス制御の段階 1： 接続確認」 を参照してください。)</p></blockquote>
<p>分かったような、わからないような。参照先を見てみるとより詳しい説明がある。</p>
<p>4.7.5. アクセス制御の段階 1： 接続確認<br />
<a href="http://dev.mysql.com/doc/refman/5.1/ja/connection-access.html" target="_blank"> http://dev.mysql.com/doc/refman/5.1/ja/connection-access.html</a></p>
<p>長いので引用は避けるが、MySQLがuserテーブルに書かれた情報をどのようにソートして使用しているかが影響しているようだ。上のページの説明によると、以下の順でソートを行っている。</p>
<ol>
<li>最も具体的なホスト名(つまり、%のように明示的でない指定は後回し)</li>
<li>最も具体的なユーザ名</li>
</ol>
<p>つまり、はじめの方に出てきたユーザのテーブルは、実際には以下のように並んでいることになる。</p>
<pre>

+-----------+----------+
| host      | user     |
+-----------+----------+
| localhost | root     |
| localhost |          |
| 127.0.0.1 | root     |
| %         | testuser |
+-----------+----------+
</pre>
<p>ログイン時のユーザ名とホスト名の組み合わせは、このようにソートしたテーブルを上から順に検索していき、最初に一致したもので認証が行われる。</p>
<p>ここで、「testuser」というユーザがlocalhostからアクセスしてくると、2行目の「localhostの匿名ユーザ(userが空白 = 匿名ユーザ)」に先に一致してしまうのである。<br />
この裏付けに、パスワードなしでtestuserでログインできるようにしてみると、確かに実際には匿名ユーザとしてログインしてしまっていることがわかる。</p>
<pre>

$ mysql -utestuser

mysql&gt; select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0.00 sec)
</pre>
<p>従って、「testuser@localhost」としてログインしたいなら、明示的に</p>
<pre>

mysql&gt; grant select on hoge.* to testuser@'localhost' identified by 'password';
</pre>
<p>とも実行して、「localhostのtestuser」を作成する必要がある。</p>
<p><span style="text-decoration: underline;">注 : セキュリティ上、ホストを「%」でワイルドカード指定するのはよろしくないので、やらないようにしましょう(汗)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/mysql/user-at-localhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/mysql/user-at-localhost/" />
	</item>
		<item>
		<title>MySQLでテーブルの行数を数える</title>
		<link>http://b.l0g.jp/mysql/counting-row-num/</link>
		<comments>http://b.l0g.jp/mysql/counting-row-num/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 06:24:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=921</guid>
		<description><![CDATA[テーブル内の行数を数えるのに一番簡単なのは、 select count(*) from 'テーブル名'; と実行することだが、これだと最悪そのテーブルを総なめすることになる。 こういう時はinformation sche [...]]]></description>
			<content:encoded><![CDATA[<p>テーブル内の行数を数えるのに一番簡単なのは、</p>
<pre>
select count(*) from 'テーブル名';
</pre>
<p>と実行することだが、これだと最悪そのテーブルを総なめすることになる。<br />
こういう時はinformation schemaから情報を引く。information_schema.tablesテーブルのtable_rowsカラムが行数。</p>
<pre>
mysql&gt; select table_schema, table_name, table_rows from information_schema.tables
    -&gt; where table_schema = 'hoge';
+--------------------+---------------------------------------+------------+
| table_schema       | table_name                            | table_rows |
+--------------------+---------------------------------------+------------+
| hoge               | wp_FollowMe_Links                     |          2 |
| hoge               | wp_commentmeta                        |        180 |
| hoge               | wp_comments                           |         60 |
| hoge               | wp_ktaisession                        |          0 |
| hoge               | wp_links                              |          7 |
| hoge               | wp_options                            |        236 |
| hoge               | wp_postmeta                           |        509 |
| hoge               | wp_posts                              |        323 |
| hoge               | wp_term_relationships                 |         39 |
| hoge               | wp_term_taxonomy                      |          9 |
| hoge               | wp_terms                              |          9 |
| hoge               | wp_usermeta                           |         31 |
| hoge               | wp_users                              |          2 |
+--------------------+---------------------------------------+------------+
</pre>
<p>showを使っても行数を引くことができるが、showの性質上表示させるカラムなどを細かく指定できず使いづらいこともあるので、information_schemaを引く方が好き。</p>
<pre>
show table status;
</pre>
<p>なおこれらのコマンドで引ける行数は、MyISAMなどのストレージエンジンでは正確な値だが、InnoDBの場合は概算値となる。なので、InnoDBの場合はselect count(*)するしかない。</p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/mysql/counting-row-num/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/mysql/counting-row-num/" />
	</item>
		<item>
		<title>Ubuntu Server 11.04マシンでUSB無線LANアダプタを使う</title>
		<link>http://b.l0g.jp/linux/usbwlan-ubuntuserver/</link>
		<comments>http://b.l0g.jp/linux/usbwlan-ubuntuserver/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 07:17:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=900</guid>
		<description><![CDATA[少し前に自宅で色々と検証したりするために、HP ML110 G6を買い、Ubuntu Server 11.04をインストールした。自宅は通信費節約のため、固定回線を引かず、外出時もそのまま使えるようにUQ WiMAXの回 [...]]]></description>
			<content:encoded><![CDATA[<p>少し前に自宅で色々と検証したりするために、<a href="http://nttxstore.jp/_II_HP13476513" target="_blank">HP ML110 G6</a>を買い、Ubuntu Server 11.04をインストールした。自宅は通信費節約のため、固定回線を引かず、外出時もそのまま使えるようにUQ WiMAXの回線を契約し、<a href="http://121ware.com/product/atermstation/product/wimax/wm3500r/" target="_blank">Aterm WM3500R</a>という無線LANルータを使っている。このため、ML110を無線LAN接続する必要がある。</p>
<p>近くのビックカメラで、安くて小さいUSB無線LANアダプタとしてプラネックスのGW-USNano2-Mを買ってきて、無線LANルータ経由でインターネットに接続するまでのメモ。</p>
<p><iframe style="width: 120px; height: 240px;" src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=l0gjp-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=B004AP8QLQ" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="320" height="240"></iframe></p>
<p>Ubuntu DesktopならGUIツールであれこれできるが、Serverなので全部CLIで。</p>
<h2>ドライバパッケージをダウンロード</h2>
<p>GW-USNano2-?(MやG)は、RealtekのRTL8192CUという無線LANチップを使っているようなので、これに対応したドライバをダウンロード。<a href="http://www.realtek.com.tw/downloads/" target="_blank">Realtekのダウンロードページ</a>を開き、以下のようにリンクをたどる</p>
<ol>
<li>Communications Network ICs</li>
<li>Wireless LAN ICs</li>
<li>WLAN NIC</li>
<li>IEEE 802.11b/g/n Single-Chip</li>
<li>Software</li>
<li>RTL8192CUにチェックし、goボタン</li>
<li>「Linux driver for Kernel 2.6.38(and earlier)」から、RTL8192CU_linux_v3.1.2590.20110922.zipをダウンロード</li>
</ol>
<h2>ドライバのインストール</h2>
<p>パッケージを展開し、コンパイル、インストール</p>
<pre>
$ unzip RTL8192CU_linux_v3.1.2590.20110922.zip
$ cd RTL8192CU_8188CUS_8188CE-VAU_linux_v3.1.2590.20110922/
$ sudo sh install.sh
</pre>
<p>※ Ubuntu Serverをインストールした直後は、makeやgccがインストールされないので、事前にsudo apt-get install make gccしておく。</p>
<p>インストールされたら、ドライバモジュールがロードされていることを確認</p>
<pre>
$ lsmod
Module Size Used by
nls_utf8 12557 0
isofs 40283 0
vesafb 13761 1
8192cu 508081 0 ← ロードされている
lp 17789 0
parport 46458 1 lp
usbhid 46956 0
hid 91020 1 usbhid
tg3 141750 0
</pre>
<h2>無線LAN設定</h2>
<p>WPA認証情報をファイルに書き込む。SSIDとキーは使用している無線LANアクセスポイントのものに置き換える。</p>
<pre>
$ wpa_passphrase [SSID] [キー] &gt; wpa_supplicant.conf
$ sudo mv wpa_supplicant.conf /etc/wpa_supplicant/
$ sudo chown root:root /etc/wpa_supplicant/wpa_supplicant.conf
</pre>
<p>認証の設定を/etc/network/interfaceに設定を書き込む。DHCPを使用する場合の例。3行目のSSIDは上と同じく置き換えること。</p>
<pre>
auto wlan0
iface wlan0 inet dhcp
wpa-essid [SSID]
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
</pre>
<p>マシンを再起動</p>
<pre>
$ sudo reboot
</pre>
<p>再起動後、wlan0というインタフェースができており、ネットワークに接続できればOK。iwconfigコマンドで無線インタフェースの状態を確認できる。</p>
<pre>
lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:&quot;aterm-xxxxxx-g&quot;  Nickname:&quot;&lt;WIFI@REALTEK&gt;&quot;
          Mode:Managed  Frequency:2.412 GHz  Access Point: xx:xx:xx:xx:xx:xx
          Bit Rate:150 Mb/s   Sensitivity:0/0
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=47/100  Signal level=47/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/linux/usbwlan-ubuntuserver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/linux/usbwlan-ubuntuserver/" />
	</item>
		<item>
		<title>historyに時刻を記録する</title>
		<link>http://b.l0g.jp/shell/history-with-timestamp/</link>
		<comments>http://b.l0g.jp/shell/history-with-timestamp/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 15:05:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[シェル]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=890</guid>
		<description><![CDATA[bash 3.0以上(最近のLinuxは大抵3.0以上)を使用している場合は、「HISTTIMEFORMAT」というシェル変数に時刻のフォーマットを入れることで、historyコマンドの実行結果(ファイル)にコマンドだけ [...]]]></description>
			<content:encoded><![CDATA[<p>bash 3.0以上(最近のLinuxは大抵3.0以上)を使用している場合は、「HISTTIMEFORMAT」というシェル変数に時刻のフォーマットを入れることで、historyコマンドの実行結果(ファイル)にコマンドだけではなく時刻も記録できる。以下はhistoryコマンドの実行結果の例。</p>
<pre>
100  2011-11-22 10:16:59 ls
101  2011-11-22 10:17:03 cd /var/log/
102  2011-11-22 10:17:04 ls
</pre>
<p>ホームディレクトリ以下の.bashrcや/etc/profile(全ユーザに適用したい場合)に</p>
<pre>
HISTTIMEFORMAT='%Y-%m-%d %T '
</pre>
<p>と書いておけばよい。時刻のフォーマットはdateコマンドと同じものが使えるようだ(man dateを参照)。</p>
<p>なお、historyコマンドでは上記のようなフォーマットが有効だが、.bash_historyファイルには、</p>
<pre>
#1321924619
ls
#1321924623
cd /var/log/
#1321924624
ls
</pre>
<p>のように、UNIX時刻が付加される形で記録される。</p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/shell/history-with-timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/shell/history-with-timestamp/" />
	</item>
		<item>
		<title>携帯キャリアの使用するIPアドレス帯一覧</title>
		<link>http://b.l0g.jp/uncategorized/carrier-ipaddress/</link>
		<comments>http://b.l0g.jp/uncategorized/carrier-ipaddress/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 13:30:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=878</guid>
		<description><![CDATA[携帯キャリアのIPアドレス帯を調べる機会があったので、メモとして載せておく。ソフトバンクは2011年9月30日からサイトのアドレスが変わっているので注意。 auフィーチャーフォンhttp://www.au.kddi.co [...]]]></description>
			<content:encoded><![CDATA[<p>携帯キャリアのIPアドレス帯を調べる機会があったので、メモとして載せておく。ソフトバンクは2011年9月30日からサイトのアドレスが変わっているので注意。</p>
<ul>
<li>auフィーチャーフォン<br /><a href="http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html" target="_blank">http://www.au.kddi.com/ezfactory/tec/spec/ezsava_ip.html</a></li>
<li>auフィーチャーフォンメール<br /><a href="http://www.au.kddi.com/service/email/support/chui/shiyo/iip_ichiran.html " target="_blank">http://www.au.kddi.com/service/email/support/chui/shiyo/iip_ichiran.html</a></li>
<li>docomoフィーチャーフォン<br /><a href="http://www.nttdocomo.co.jp/service/developer/make/content/ip/ " target="_blank">http://www.nttdocomo.co.jp/service/developer/make/content/ip/</a></li>
<li>docomoスマートフォン(spモード)<br /><a href="http://www.nttdocomo.co.jp/service/developer/smart_phone/technical_info/etc/index.html " target="_blank">http://www.nttdocomo.co.jp/service/developer/smart_phone/technical_info/etc/index.html</a></li>
<li>softbankフィーチャーフォン<br /><a href="http://creation.mb.softbank.jp/mc/tech/tech_web/web_ipaddress.html " target="_blank">http://creation.mb.softbank.jp/mc/tech/tech_web/web_ipaddress.html</a></li>
<li>softbankフィーチャーフォンメール<br /><a href="http://creation.mb.softbank.jp/mc/tech/tech_mail/mail_ipaddress.html " target="_blank">http://creation.mb.softbank.jp/mc/tech/tech_mail/mail_ipaddress.html</a></li>
<li>softbankスマートフォン<br /><a href="https://www.support.softbankmobile.co.jp/partner/home_tech1/index.cfm " target="_blank">https://www.support.softbankmobile.co.jp/partner/home_tech1/index.cfm</a></li>
<li>softbankスマートフォンメール<br /><a href="https://www.support.softbankmobile.co.jp/partner/home_tech2/index.cfm " target="_blank">https://www.support.softbankmobile.co.jp/partner/home_tech2/index.cfm</a></li>
<li>willcom<br /><a href="http://www.willcom-inc.com/ja/service/contents_service/create/center_info/ " target="_blank">http://www.willcom-inc.com/ja/service/contents_service/create/center_info/</a></li>
<li>emobile<br /><a href="http://developer.emnet.ne.jp/ipaddress.html" target="_blank"> http://developer.emnet.ne.jp/ipaddress.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/uncategorized/carrier-ipaddress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/uncategorized/carrier-ipaddress/" />
	</item>
		<item>
		<title>CentOSで各種ビープ音を鳴らさないようにする</title>
		<link>http://b.l0g.jp/linux/beep-centos/</link>
		<comments>http://b.l0g.jp/linux/beep-centos/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 14:59:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=867</guid>
		<description><![CDATA[＜ログイン時＞ Xを起動するようにしていると(ランレベル5)、ログイン画面表示時にビープ音が鳴る。 「システム(System)」→「管理(Administration)」→「ログイン画面(Login Screen)」から [...]]]></description>
			<content:encoded><![CDATA[<h4><strong>＜ログイン時＞</strong></h4>
<p>Xを起動するようにしていると(ランレベル5)、ログイン画面表示時にビープ音が鳴る。</p>
<p>「システム(System)」→「管理(Administration)」→「ログイン画面(Login Screen)」から「アクセシビリティ(Accessibility)」タブを開き、「ログイン画面を表示した時」のチェックを外す。</p>
<p>ログアウトし、次にログイン画面が表示されるときには、ビープ音は鳴らないようになっているはず。</p>
<h4><strong>＜ターミナル使用時＞</strong></h4>
<p>ターミナルを使用している時にタブを使ったりすると、ビープ音が鳴ることがある。</p>
<p>/etc/inputrc に以下の行を追加する(コメントアウトされた状態で既に記述があるはず)</p>
<pre>

set bell-style none
</pre>
<p>ログインしなおすと、設定が有効になりビープ音は鳴らなくなる。</p>
<h4><strong>＜vi＞</strong></h4>
<p>vi(vim)を使用していると、コマンドを間違えた時などにビープ音が鳴る。</p>
<p>viの設定ファイル(ホームディレクトリの.vimrcや/etc/skel/.vimrcなど)に以下の行を追加する。</p>
<pre>

set visualbell
</pre>
<p>記述してからviを起動すると、ビープ音は鳴らなくなる。</p>
<h4><strong>＜全部のビープ音を鳴らないようにする＞</strong></h4>
<p>ビープ音は、pcspkrというモジュールを経由して、マザーボード上のスピーカを動かして鳴らしている。このモジュール自体をロードしないようにしてしまえば、ビープ音は鳴らない。</p>
<p>/etc/modprobe.d/blacklist ファイルに以下の行を追加する。</p>
<pre>

blacklist pcspkr
</pre>
<h4><strong>＜VMware Playerを使用している場合＞</strong></h4>
<p>VMware Playerを使用している時には、ゲストOSでビープ音が鳴るタイミングで、VMware Playerを通じて、ホストマシンのビープ音が鳴ってしまう。これを鳴らさないようにするには、VMware側の設定でビープを無効にしてしまう。</p>
<p>C:\Users\(ユーザ名)\AppData\Roaming\VMware\preferences.ini ファイルと、対象になる仮想マシンの設定ファイル(.vmx)に以下の行を追加する。</p>
<pre>

mks.noBeep = &quot;TRUE&quot;
</pre>
<p>出典 : <a href="http://kb.vmware.com/kb/1664" target="_blank">VMwareのKnowledge base</a></p>
<h4><strong>＜Windowsでビープ音を鳴らさないようにする＞</strong></h4>
<p>ついでにWindowsの場合も。ビープ音を鳴らすドライバを無効にしてしまう。以下、Windows 7での例。</p>
<ol>
<li>コントロールパネルなどから「デバイスマネージャ」を起動</li>
<li> 「表示」→「非表示のデバイスの表示」</li>
<li>ツリーから「プラグアンドプレイではないドライバ」→「Beep」を右クリックし、プロパティ</li>
<li> 「ドライバー」タブで「停止」を選択</li>
</ol>
<p>以上</p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/linux/beep-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/linux/beep-centos/" />
	</item>
		<item>
		<title>bshでのクォーテーションの入れ子</title>
		<link>http://b.l0g.jp/shell/bsh-nested-quotation/</link>
		<comments>http://b.l0g.jp/shell/bsh-nested-quotation/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:30:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[シェル]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=861</guid>
		<description><![CDATA[特殊文字(？など)をそのまま文字として扱いたい場合などに、シングルクォーテーション(&#8216;)やダブルクォーテーション(&#8220;)で文字をくくる。 「&#8221;」でくくった文字列は、その中に特殊文字が含ま [...]]]></description>
			<content:encoded><![CDATA[<p>特殊文字(？など)をそのまま文字として扱いたい場合などに、シングルクォーテーション(&#8216;)やダブルクォーテーション(&#8220;)で文字をくくる。</p>
<ul>
<li>「&#8221;」でくくった文字列は、その中に特殊文字が含まれているならそれを展開する。</li>
<li>「&#8217;」でくくった文字列は、その中に特殊文字が含まれていてもそれを展開せず、そのまま表示する。</li>
</ul>
<pre>
[hoge@symf test]$ abc=3
  ↑ abcという変数に3を代入
[hoge@symf test]$ echo $abc
3
  ↑ abcという変数の中身を表示
[hoge@symf test]$ echo &quot;$abc&quot;
3
  ↑ 「&quot;」は特殊文字を展開するので変数として扱われるので、上に同じ
[hoge@symf test]$ echo '$abc'
$abc
  ↑ 「'」は特殊文字をそのまま表示する
</pre>
<p>クォーテーションを入れ子にする際には、シングルとダブルで少しやり方が違う。「man bash」の「クォート」の項には以下のように書かれている。</p>
<blockquote><p>シングルクォートで文字を囲むと、クォート内部のそれぞれの文字は文字としての値を 保持 します。シングルクォートの間にシングルクォートを置くことはできません。これはバックスラッシュを前に付けても同じです。</p></blockquote>
<blockquote><p>ダブルクォートで文字を囲むとクォート内部の全ての文字は文字としての値を保持しま すが、 $, ‘, \ は例外となります。 $ と ‘ はダブルクォートの内部でも特殊な意味を失いません。バックスラッシュの場合は、次の文字が $, ‘, &#8220;, \,のいずれかである 場合に限り特殊な意味を失いません。前にバックスラッシュを付ければ、ダブルクォート文字をダブルクォートによるクォートの内部でクォートできます。</p></blockquote>
<p>つまりこういうこと。</p>
<pre>
[hoge@symf test]$ ssh server &quot;psql -c \&quot;create database test with ENCODING = 'UTF8' ;\&quot; &quot;
  ↑ 「&quot;」の中に「\&quot;」があるので、これは成功

[hoge@symf test]$ ssh server 'psql -c \&quot;create database test with ENCODING = 'UTF8' ;\&quot; '
  ↑ 「'」の中では「\」をつけてもダメなので、これは失敗
</pre>
<p>create databaseじゃなくてcreatedbを使えば、クォートを入れ子にしなくてもいいって？あくまで例ですから (`・ω・´)ｷﾘｯ</p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/shell/bsh-nested-quotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/shell/bsh-nested-quotation/" />
	</item>
		<item>
		<title>shのwhileループでファイルを読み、中でsshを実行すると1回しかループしない</title>
		<link>http://b.l0g.jp/dev/ssh-inside-while/</link>
		<comments>http://b.l0g.jp/dev/ssh-inside-while/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 05:39:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[開発]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=690</guid>
		<description><![CDATA[シェル(sh)スクリプトネタ。 while 文で以下のように指定すると、行ごとにファイルを読み込むことができる。 #!/bin/sh # ファイルを1行ずつ読み込んで表示 TESTFILE=./hoge.txt whil [...]]]></description>
			<content:encoded><![CDATA[<p>シェル(sh)スクリプトネタ。</p>
<p>while 文で以下のように指定すると、行ごとにファイルを読み込むことができる。</p>
<pre>
#!/bin/sh

# ファイルを1行ずつ読み込んで表示

TESTFILE=./hoge.txt

while read line
do
echo $line
done &lt; $TESTFILE
</pre>
<p>しかし、 while ループの中で ssh や rsh を実行すると、読み込むファイルが複数行あっても、1行目しか処理されない。</p>
<pre>
#!/bin/sh

# TESTFILEが複数行あっても1行目のみ処理されてループ終了

while read line
do
ssh 192.168.0.1 touch $line
done &lt; $TESTFILE
</pre>
<p>SSH を実行すると、標準入力がそちらに振り向けられるため、read で読んだ1行のみならず、ファイル全体が SSH に渡されてしまう。従って、SSH を実行した後はもう読める行がないので while ループは1回で終了してしまう。</p>
<p>これを防ぐには、ssh に -n オプションを付け、/dev/null をリダイレクトし、標準入力をリダイレクトしないようにする。</p>
<pre>
#!/bin/sh

# TESTFILEが複数行あればその行数分処理が実行される

while read line
do
ssh -n 192.168.0.1 touch $line
done &lt; $TESTFILE
</pre>
<p>なおこれは rsh コマンドでも同じ仕様になっているようだ。</p>
<p>なぜ1行目だけで終わってしまうのか分からずうんうんうなってたら、この本に書いてあった。</p>
<p><iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=l0gjp-22&#038;o=9&#038;p=8&#038;l=as4&#038;m=amazon&#038;f=ifr&#038;ref=ss_til&#038;asins=4797321946" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/dev/ssh-inside-while/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/dev/ssh-inside-while/" />
	</item>
		<item>
		<title>ディレクトリをディレクトリにマウント</title>
		<link>http://b.l0g.jp/dev/mounting-directory-on-directory/</link>
		<comments>http://b.l0g.jp/dev/mounting-directory-on-directory/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 14:42:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[開発]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=682</guid>
		<description><![CDATA[Linuxで、ディスクデバイスではなく、ディレクトリをディレクトリにマウントしたい時は mount --bind マウントしたいディレクトリ マウントポイント fstabに書いてしまうときは以下のように書く。 マウントし [...]]]></description>
			<content:encoded><![CDATA[<p>Linuxで、ディスクデバイスではなく、ディレクトリをディレクトリにマウントしたい時は</p>
<pre>
mount --bind マウントしたいディレクトリ マウントポイント
</pre>
<p>fstabに書いてしまうときは以下のように書く。</p>
<pre>
マウントしたいディレクトリ マウントポイント none bind 0 0
</pre>
<p>例えば /home を /hoge/home としてマウントしたい時は</p>
<pre>
/home /hoge/home none bind 0 0
</pre>
<p>なお、マウントしたいディレクトリ(上の例では/hoge)よりも後にこの行を書かないと、マウントできないので注意。</p>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/dev/mounting-directory-on-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/dev/mounting-directory-on-directory/" />
	</item>
		<item>
		<title>sarコマンドでシステムのボトルネックを探る(2)</title>
		<link>http://b.l0g.jp/dev/finding-bottleneck-with-sar2/</link>
		<comments>http://b.l0g.jp/dev/finding-bottleneck-with-sar2/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 13:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[開発]]></category>

		<guid isPermaLink="false">http://b.l0g.jp/?p=673</guid>
		<description><![CDATA[CPUの処理の状況を調べるためには、sar (sar -u)が有効であることを前のエントリで書いた。次はメモリの使用状況を調べてみる。まず見てみるのは、メモリとスワップの使用状況を示す sar -r の結果である。 [d [...]]]></description>
			<content:encoded><![CDATA[<p>CPUの処理の状況を調べるためには、sar (sar -u)が有効であることを<a href="http://b.l0g.jp/dev/finding-bottleneck-with-sar1/" target="_blank">前のエントリ</a>で書いた。次はメモリの使用状況を調べてみる。まず見てみるのは、メモリとスワップの使用状況を示す sar -r の結果である。</p>
<pre>
[doublemarket@hoge ~]$ sar -r
Linux 2.6.18-194.8.1.el5 (hoge)       2011年02月15日

00時00分01秒 kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
00時10分01秒     12964    497568     97.46     30880    107440   1984336     63940      3.12     16392
00時20分01秒     13064    497468     97.44     30972    107376   1984336     63940      3.12     16392
00時30分01秒     12692    497840     97.51     31092    107236   1984336     63940      3.12     16392
:
:
20時20分01秒     43756    466776     91.43     45624    139552   1984336     63940      3.12     16288
20時30分01秒     27008    483524     94.71     46420    147608   1984336     63940      3.12     16288
20時40分01秒     22664    487868     95.56     46840    148920   1984336     63940      3.12     16288
20時50分01秒     22300    488232     95.63     47192    148968   1984336     63940      3.12     16288
平均値:      84267    426265     83.49     32592    129944   1984336     63940      3.12     16300
</pre>
<p>それぞれの列の意味は以下の通り。</p>
<dl>
<dt style="padding-left: 30px;"><strong>kbmemfree</strong></dt>
<dd style="padding-left: 60px;">物理メモリの未使用KB。</dd>
<dt style="padding-left: 30px;"><strong>kbmemused</strong></dt>
<dd style="padding-left: 60px;">物理メモリの使用済みKB。</dd>
<dt style="padding-left: 30px;"><strong>%memused</strong></dt>
<dd style="padding-left: 60px;">物理メモリの使用率。Linuxでは、使用されていないメモリ領域をファイルシステムキャッシュ領域として使用するので、通常はほとんどfree部分はないものと考えてよい。従って、常に90数%といった高い使用率になる。実際にアプリケーションの動作に使われているメモリの量は、下の指標を確認する必要がある。</dd>
<dt style="padding-left: 30px;"><strong>kbbuffers</strong></dt>
<dd style="padding-left: 60px;">カーネルがバッファ領域として使用しているメモリ量のKB。</dd>
<dt style="padding-left: 30px;"><strong>kbcached</strong></dt>
<dd style="padding-left: 60px;">カーネルがキャッシュとして使用しているメモリ量のKB。kbmemusedからkbbufferesとkbcachedを引いた値が、実際にアプリケーションに割り当てられているメモリ量ということになる。逆に言えば、kbbufferesとkbcachedの容量が、kbmemusedの大部分を占めているようなら、アプリケーションにとってメモリ不足とは言えないということになる。</dd>
<dt style="padding-left: 30px;"><strong>kbswpfree</strong></dt>
<dd style="padding-left: 60px;">スワップ領域の未使用量KB。</dd>
<dt style="padding-left: 30px;"><strong>kbswpused</strong></dt>
<dd style="padding-left: 60px;">スワップ領域の使用済みKB。</dd>
<dt style="padding-left: 30px;"><strong>%swpused</strong></dt>
<dd style="padding-left: 60px;">スワップ領域の使用量。通常ほとんど0だが、物理メモリが不足してくると使用率が上がってくる。数%であれば実質的にシステムの動作には影響がない場合が多いが、あまり多いようだと、スワップ領域へのアクセスが頻発している可能性もあり、システム全体のスループットを落とすことがある。%swpusedが大きく、かつsar -uのiowaitの値も大きい場合、ほぼ間違いなくスワップ領域へのアクセスでスローダウンしているので、物理メモリの増設などのメモリ不足解消策を取る必要がある。</dd>
<dt style="padding-left: 30px;"><strong>kbswpcad</strong></dt>
<dd style="padding-left: 60px;">何の指標かよく分からなかったが、manページによると、一旦スワップ領域へ飛ばされたものの(スワップアウト)、スワップ領域からメモリに戻され(スワップイン)、かつまだスワップ領域にデータが残っている、というデータの量とのこと。</dd>
</dl>
<p>各列の値の傾向を見ると、上記のようにメモリ不足なのかどうかの手がかりが得られる。その他に詳しい情報を見たいときは、以下のオプションも用意されている。</p>
<dl>
<dt style="padding-left: 30px;"><strong>sar -R</strong></dt>
<dd style="padding-left: 60px;">メモリ上のページの使用状況。</dd>
<dt style="padding-left: 30px;"><strong>sar -W</strong></dt>
<dd style="padding-left: 60px;">スワップの発生状況。ページイン(スワップ領域から物理メモリへのページの移動)とページアウト(物理メモリからスワップ領域へのページの移動)がどの程度発生したのかを確認できる。</dd>
<dt style="padding-left: 30px;"><strong>sar -B</strong></dt>
<dd style="padding-left: 60px;">ページングの状況。ページイン・ページアウトされたデータ容量、ページフォルトの回数、メジャーなページフォルトの回数をそれぞれ確認できる。</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://b.l0g.jp/dev/finding-bottleneck-with-sar2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://b.l0g.jp/dev/finding-bottleneck-with-sar2/" />
	</item>
	</channel>
</rss>

