<?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/"
	>

<channel>
	<title>Yukun&#039;s Blog &#187; Linux</title>
	<atom:link href="http://www.yukun.info/blog/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yukun.info</link>
	<description>難しいことは分かりやすく、簡単なことは面白く紹介</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:33:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Linux: RedmineとSubversionのインストール・設定例</title>
		<link>http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html</link>
		<comments>http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html#comments</comments>
		<pubDate>Mon, 05 Dec 2011 15:00:09 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Redmine]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Setting]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=2041</guid>
		<description><![CDATA[Linux(ここではCentOS)にプロジェクト管理ソフトウェアであるRedmineとバージョン管理システムであるSubversionのインストール方法と設定例を以下に紹介。想定としては、WebサーバやDB以外は何も設定 &#8230; <a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html">Linux: RedmineとSubversionのインストール・設定例</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Linux(ここではCentOS)にプロジェクト管理ソフトウェアであるRedmineとバージョン管理システムであるSubversionのインストール方法と設定例を以下に紹介。想定としては、WebサーバやDB以外は何も設定されていないサーバ環境を対象とした手順。すでにインストールしているものや設定済みのものは適時読み飛ばし下さい。<br />
※参考サイトは記事の末尾をご参照。</p>
<p><span id="more-2041"></span></p>
<h3>1. 開発環境のインストール</h3>
<p>RubyやPassengerのインストールに必要なコンパイラをインストールする。</p>
<pre>
# yum groupinstall "Development Tools"
# yum install openssl-devel readline-devel zlib-devel curl-devel
</pre>
<h3>2. Rubyのインストール</h3>
<p>Redmineを動作させる上でパフォーマンスの良いruby-enterpriseを以下のサイトよりダウンロード。<br />
<a href="http://www.rubyenterpriseedition.com/download.html" target="_blank">Ruby Enterprise Edition</a></p>
<pre>
# tar xzvf ruby-enterprise-1.8.7-2011.03.tar.gz
# ruby-enterprise-1.8.7-2011.03/installer --dont-install-useful-gems --no-dev-docs
# ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03
</pre>
<h3>3. rubygemsのインストール</h3>
<p>下記のサイトよりダウンロードする。<br />
<a href="http://rubyforge.org/frs/?group_id=126" target="_blank">RubyForge: RubyGems: Project Filelist</a></p>
<pre>
# tar zxvf rubygems-1.5.2.tgz
# cd rubygems-1.5.2
# ruby setup.rb config
# ruby setup.rb setup
# ruby setup.rb install
</pre>
<h3>4. gemで必要コンポーネントのインストール</h3>
<pre>
# gem install rack -v=1.1.1 --no-rdoc --no-ri
# gem install rake -v=0.8.7 --no-rdoc --no-ri
# gem install i18n -v=0.4.2 --no-rdoc --no-ri
# gem install mysql -- --with-mysql-lib=/usr/lib/mysql --no-rdoc --no-ri
</pre>
<p>仮に以下のエラーが発生した場合。。。</p>
<pre>
Fetching: mysql-2.8.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... 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.
</pre>
<p>パッケージのインストール不足の為、yumでmysql-server mysql-develを依存含めてインストールする。<br />
MySQLのインストールリポジトリをremiやeplpとしている場合はbaseと競合しないように以下のように設定する。</p>
<pre>
# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
priority=1
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&#038;arch=$basearch&#038;repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
exclude=mysql*　←mysqlで始まるものは除外(複数指定したいときはカンマ「,」で区切る)
# yum --enablerepo=remi,eplp install mysql-server mysql-devel
</pre>
<p>その上で、再度以下のコマンドを実行する。</p>
<pre>
# gem install mysql -- --with-mysql-lib=/usr/lib/mysql --no-rdoc --no-ri
</pre>
<h3>5. Webサーバ(Apache)のインストール</h3>
<p>とは言いつつも、ここは既にインストール＆設定されている前提で進める。</p>
<pre>
# yum install httpd httpd-devel
</pre>
<h3>6. MySQLのDB作成・設定</h3>
<p>MySQLも基本的な文字コードなどのmy.cnf設定は済んでいる前提で進める。</p>
<pre>
# mysql -u root -p
mysql> show variables like 'character_set%';　←為念の確認
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
mysql> create database ＜DB名＞ default character set utf8;
mysql> grant all on ＜DB名＞.* to ＜DBユーザー名＞ identified by '＜DBパスワード＞';
mysql> flush privileges;
mysql> exit;
</pre>
<h3>7. Redmineのインストール</h3>
<p>以下のサイトからRedmineをダウンロードする。</p>
<p><a href="http://rubyforge.org/frs/?group_id=1850" target="_blank">RubyForge: Redmine: ファイルリスト</a></p>
<pre>
# tar xzvf redmine-1.2.2.tar.gz
# mv redmine-1.2.2 /var/lib/redmine
# cd /var/lib/redmine
# vi config/database.yml
production:
  adapter: mysql
  database: ＜DB名＞
  host: localhost
  username: ＜DBユーザー名＞
  password: ＜DBパスワード＞
  encoding: utf8

# cp config/configuration.yml.example config/configuration.yml
# vi config/configuration.yml
production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: 'example.com'
</pre>
<p>DBやメールの設定をファイルに書き込んだ後は、セッションキーの作成および、DBテーブルの作成・初期化を以下のコマンドで実施する。</p>
<pre>
# rake generate_session_store
# rake db:migrate RAILS_ENV=production
</pre>
<h3>8. Passengerをインストール</h3>
<p>Apache上でrailsを使用する為にPassengerをインストール・設定する。</p>
<pre>
# gem install passenger --no-rdoc --no-ri
# passenger-install-apache2-module
</pre>
<p>コマンド実行後最後に出力される下記のパスをメモ帳などに控えておく。<br />
(LoadModule passenger_module、PassengerRoot、PassengerRuby )</p>
<blockquote><p>
Please edit your Apache configuration file, and add these lines:</p>
<p>   LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.9/ext/apache2/mod_passenger.so<br />
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.9<br />
   PassengerRuby /usr/local/bin/ruby</p>
<p>After you restart Apache, you are ready to deploy any number of Ruby on Rails<br />
applications on Apache, without any further Ruby on Rails-specific<br />
configuration!
</p></blockquote>
<h3>9. Apacheの設定(サブディレクトリ配置の場合)</h3>
<p>例としてwww.example.comドメインの配下www.example.com/redmine_top/がredmineのトップページとする設定例を紹介する。</p>
<pre>
# vi /etc/httpd/conf.d/passenger.conf ←Passenger用の設定ファイルを作成
#（上述で表示されたパスを記述する）
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby

RailsBaseURI /redmine_top

Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0
</pre>
<p>最後に権限・パス設定後、それらを反映する。</p>
<pre>
# chown -R apache:apache /var/lib/redmine
# ln -s /var/lib/redmine/public /var/www/html/redmine_top
# /etc/init.d/httpd configtest
# /etc/init.d/httpd graceful
</pre>
<h3>10. Redmineへアクセス</h3>
<p>www.example.com/redmine_top/にアクセスするとredmineのトップページが表示されればOK。まずはユーザー名、パスワードをadmin, adminで入りユーザ名、パスワードを任意の文字列に変更の上、各種設定を確認していく。</p>
<h3>11. Subversionのインストールとリポジトリの作成</h3>
<p>先ずは、インストールとリポジトリの作成を実施。</p>
<pre>
# yum install subversion
# mkdir /var/lib/svn
# svnadmin create /var/lib/svn/＜リポジトリ名＞
# chown -R apache:apache /var/lib/svn/＜リポジトリ名＞
</pre>
<p>続いてWeb経由でリポジトリにアクセスかつBasic認証機能で閲覧者を制限するには、</p>
<pre>
# yum install mod_dav_svn
# touch /etc/httpd/conf/svn_auth_file
# htpasswd /etc/httpd/conf/svn_auth_file ＜任意のユーザー名＞
New password: ＜タイプ＞
Re-type new password: ＜もう一度タイプ＞
Adding password for user ＜任意のユーザー名＞
</pre>
<pre>
# vi /etc/httpd/conf/httpd.conf
</pre>
<p>↓下記の設定をファイル末尾に追加</p>
<pre>
&lt;Location /svn&gt;
        DAV svn
        SVNParentPath /var/lib/svn
        AuthType Basic
        AuthName &quot;svn repository&quot;
        AuthUserFile /etc/httpd/conf/svn_auth_file
        Require valid-user
&lt;/Location&gt;
</pre>
<p>www.example.com/svn/＜リポジトリ名＞ でアクセス可能となる。Basic認証を用いてredmineと連携する場合は、redmine用の認証ユーザーを別途作成しredmineに設定すればOK。</p>
<p>何かご質問などありましたら、ご連絡下さい。</p>
<h3>参考サイト</h3>
<ul>
<li><a href="http://blog.redmine.jp/articles/redmine-1_2-installation_centos/" target="_blank">Redmine 1.2をCentOS5.6にインストールする手順</a>
</li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/12/how-to-write-apache-conf.html" rel="bookmark" title="2008年12月25日">Apacheでよく使うコマンドと設定項目</a></li>
<li><a href="http://www.yukun.info/blog/2010/03/java-install-sen-windows.html" rel="bookmark" title="2010年3月25日">Java: 形態素解析Senをインストール(Windows編)</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/vmware-player-centos.html" rel="bookmark" title="2011年2月23日">VMware PlayerでCentOSをインストール</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/cygwin-cron.html" rel="bookmark" title="2008年1月8日">Cygwinでcronをインストール</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/fedora-yum-install-gnome.html" rel="bookmark" title="2008年9月15日">FedoraにGUI環境GNOMEをyumでインストール</a></li>
</ul>
<p><!-- Similar Posts took 35.649 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html">Linux: RedmineとSubversionのインストール・設定例</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: 解決策→「要求されたアクションを実行するには、WordPress が Web サーバーにアクセスする必要があります。」</title>
		<link>http://www.yukun.info/blog/2011/08/wordpress-file-access.html</link>
		<comments>http://www.yukun.info/blog/2011/08/wordpress-file-access.html#comments</comments>
		<pubDate>Tue, 09 Aug 2011 11:11:46 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1971</guid>
		<description><![CDATA[事象 WordPressのプラグイン、テーマの自動更新をWebから実施する際に以下のメッセージが発生し、自動更新が中断。 メッセージ 要求されたアクションを実行するには、WordPress が Web サーバーにアクセス &#8230; <a href="http://www.yukun.info/blog/2011/08/wordpress-file-access.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/08/wordpress-file-access.html">WordPress: 解決策→「要求されたアクションを実行するには、WordPress が Web サーバーにアクセスする必要があります。」</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<h4>事象</h4>
<p>WordPressのプラグイン、テーマの自動更新をWebから実施する際に以下のメッセージが発生し、自動更新が中断。</p>
<h4>メッセージ</h4>
<blockquote><p>
要求されたアクションを実行するには、WordPress が Web サーバーにアクセスする必要があります。<br />
次に進むには FTP の接続情報を入力してください。 接続情報が思い出せない場合は、ホスティング担当者に問い合わせてください。
</p></blockquote>
<h4>原因・対処法</h4>
<p>apacheユーザーにpluginディレクトリへの追加や更新権限が無い為。解決策としてはwordpressの最上位フォルダ上でchown -R apache <em>＜フォルダパス＞</em>を実行しapacheの権限を付与することでOK。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/12/how-to-write-apache-conf.html" rel="bookmark" title="2008年12月25日">Apacheでよく使うコマンドと設定項目</a></li>
<li><a href="http://www.yukun.info/blog/2010/07/error-require-once-autoloader-php.html" rel="bookmark" title="2010年7月25日">解決例: 「ファイルから操作とエンティティを取得できません」 &#8211; Autoloader.php</a></li>
<li><a href="http://www.yukun.info/blog/2012/01/wordpress-remove-filter-url-link.html" rel="bookmark" title="2012年1月4日">WordPress: 本文・コメント中のURLの自動リンクを抑制する &#8211; make_clickable</a></li>
<li><a href="http://www.yukun.info/blog/2012/01/wordpress-facebook-ogp-plugins.html" rel="bookmark" title="2012年1月1日">WordPress: Facebook OGP Social Plugins(Like、コメント)の設置方法</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/wordpress-plugin-similar-posts.html" rel="bookmark" title="2008年10月12日">WordPress: Similar Posts の紹介と設定例 &#8211; 関連記事[投稿|エントリ]を表示するプラグイン</a></li>
</ul>
<p><!-- Similar Posts took 6.731 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/08/wordpress-file-access.html">WordPress: 解決策→「要求されたアクションを実行するには、WordPress が Web サーバーにアクセスする必要があります。」</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/08/wordpress-file-access.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux: シェル(Bash)の機能の概要 &#8211; 復習のための覚書(前編)</title>
		<link>http://www.yukun.info/blog/2011/08/linux-bash.html</link>
		<comments>http://www.yukun.info/blog/2011/08/linux-bash.html#comments</comments>
		<pubDate>Mon, 08 Aug 2011 13:10:19 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1949</guid>
		<description><![CDATA[シェルとは ユーザーとカーネルの間のインターフェイス。ユーザーが入力したコマンドや文字列のメタキャラクタを解釈するインタープリタ。 ログインシェル ユーザーがシステムへログインしたときに起動するシェル。ログインするシェル &#8230; <a href="http://www.yukun.info/blog/2011/08/linux-bash.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/08/linux-bash.html">Linux: シェル(Bash)の機能の概要 &#8211; 復習のための覚書(前編)</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<h4>シェルとは</h4>
<ul>
<li>ユーザーとカーネルの間のインターフェイス。ユーザーが入力したコマンドや文字列のメタキャラクタを解釈するインタープリタ。
</li>
</ul>
<p><span id="more-1949"></span></p>
<h4>ログインシェル</h4>
<ul>
<li>ユーザーがシステムへログインしたときに起動するシェル。ログインするシェルを変更する場合はchshコマンドを使用。
</li>
<li>ログインシェル上でさらに別のシェルを起動することができるが、ユーザーが使用することができるのは最後に起動したシェルのみ。
</li>
<li>ログインシェルと後に起動したシェルの見分け方はps -f。最初にハイフン「-」がついているシェルがログインシェルのプロセス。
</li>
</ul>
<pre>
$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
xxx      13450 13449  0 21:26 pts/1    00:00:00 -bash
xxx     13476 13450  0 21:26 pts/1    00:00:00 bash
xxx      13499 13476  0 21:27 pts/1    00:00:00 ksh
xxx      13501 13499  0 21:27 pts/1    00:00:00 ps –f
</pre>
<h4>シェルの種類</h4>
<ul>
<li>古いものから順にBourneシェル、Cシェル、Kornシェル、Bashとなる。
</li>
<li>BashはUNIX上のBourneシェル互換としてGUNより開発されたLinux標準シェル。
</li>
<li>LinuxでのBashの起動は$ shで(LinuxではBourneシェルはライセンス上使用できない為)。
</li>
<li>↓確かにリンクがbashへと張られている(CentOSで実行)
</li>
</ul>
<pre>
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4  7月  9 15:06 /bin/sh -> bash
</pre>
<h4>シェルスクリプトの使いどころ</h4>
<ul>
<li>Linuxコマンドの組み合わせで実現できる処理(grep, sort, sed, awk, etc…)であればシェルスクリプトを使用。特にテキスト行の処理など。
</li>
<li>数値や文字列ごとの処理を使用する場合は型変換等の負荷のため実行速度が低下するため、C言語等の高級言語を使用するのが望ましい。
</li>
</ul>
<h4>シェルスクリプトの作成と実行方法</h4>
<ul>
<li>vi, vim等のテキストエディタで作成。対象のスクリプトファイルに実行権限を付与。
</li>
<li>chmod u+x xxxxxx.sh か、
</li>
<li>chmod 744 xxxxxx.sh でOK.
</li>
<li>実行は ./xxxxxx.sh　ただし、カレントディレクトリにpathが通っている場合は先頭の./は不要となる。
</li>
<li>スクリプトの1行目のシェルの指定(絶対パス)は、#!/bin/sh, #!/bin/bashのどちらを用いてもLinux上ではBashで実行される。
</li>
<li>1行目を省略した場合は、LinuxではBashで実行される。
</li>
<li>#のみを記述すると、現在起動中のシェルと同じシェルで実行される。
</li>
</ul>
<h4>コマンドの種類</h4>
<ul>
<li>組み込みコマンド：シェル内部のコマンド(cd, exitなど)
</li>
<li>一般コマンド：実行形式ファイルのコマンド(cp, lsなど)。/binや/usr/binディレクトリ以下に実行ファイルが存在する。
</li>
<li>組み込み・一般の判別にはtypeコマンドを使用する。
</li>
<li>以下にtypeコマンドの実行例。
</li>
</ul>
<pre>
$ type cp
cp is /bin/cp
$ type cd
cd is a shell builtin
</pre>
<ul>
<li>一般コマンドがシェルで実行されると、子プロセス上で実行される。
</li>
<li>実行順序としては、一般コマンド実行時→親プロセスのforkシステムコールによる子プロセスの生成→親プロセスのwaitシステムコールによる子プロセスの処理実行待ち→子プロセスのexecシステムコールによりコマンドのロード→コマンドプログラムのexitシステムコールにより子プロセスの終了→親プロセスの後続の処理を実行…。
</li>
<li>基本的にシェルスクリプトも実行時に特に指定がなければ子プロセスを生成し実行される。
</li>
<li>シェルの変数定義のスコープはプロセス毎。
</li>
</ul>
<h4>入出力リダイレクション</h4>
<ul>
<li>標準入力(0)、標準出力(1)、標準エラー出力(2)。リダイレクト記号はそれぞれ<, 1>, 2>であるが、標準出力の1は省略可能のため、>で可能。
</li>
<li> 2>&#038;1の場合は、コマンド実行時のエラーを標準出力(1)に割り当て。
</li>
<li> $ find / -name help > findlist 2>&#038;1
</li>
</ul>
<h4>パイプによるコマンドの連携</h4>
<ul>
<li>パイプ「|」は→とみた方が直感的にわかりやすい。|の左で実行されたコマンドの出力をパイプの後に指定したコマンドの入力として使用。
</li>
<li># grep Invalid /var/log/secure | wc –l
</li>
</ul>
<h4>その他のシェルのメタキャラクタ</h4>
<ul>
<li>連続実行：１行内でのコマンドの連続実行をする場合はコマンド間にセミコロンを挿入「;」。(C言語のステートメント終了みたいだぁ)
</li>
<li>グループ化：()のコマンドを子プロセスを生成して実行。cd /; pwd ; lsの三種コマンドに括弧をつけるとカレントディレクトリを変更せずに実行結果を取得できる。
</li>
<li>親プロセスの環境の変更したくない場合や複数コマンドの実行結果を出力したい場合に利用。
</li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html" rel="bookmark" title="2011年2月6日">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html" rel="bookmark" title="2011年2月13日">Shell Script: testコマンドによる条件判定 (数値、文字列)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process-2.html" rel="bookmark" title="2008年1月10日">プロセスの監視＆自動復旧(簡易版)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process.html" rel="bookmark" title="2008年1月7日">シェルスクリプトでプロセスを監視し自動実行＆自動kill</a></li>
<li><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html" rel="bookmark" title="2011年1月30日">Shell Script: for文 &#8211; ワードリストを順に出力</a></li>
</ul>
<p><!-- Similar Posts took 10.327 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/08/linux-bash.html">Linux: シェル(Bash)の機能の概要 &#8211; 復習のための覚書(前編)</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/08/linux-bash.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: 数値と文字列の判別</title>
		<link>http://www.yukun.info/blog/2011/08/bash-if-num-str.html</link>
		<comments>http://www.yukun.info/blog/2011/08/bash-if-num-str.html#comments</comments>
		<pubDate>Fri, 05 Aug 2011 12:40:06 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[RegExp]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1944</guid>
		<description><![CDATA[手っ取り早く数字文字列とそれ以外の文字列を判別する条件式は以下のとおり。 コード #!/bin/sh if expr "$1" : '[0-9]*' > /dev/null ; then echo "数値です" else &#8230; <a href="http://www.yukun.info/blog/2011/08/bash-if-num-str.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/08/bash-if-num-str.html">Bash: 数値と文字列の判別</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>手っ取り早く数字文字列とそれ以外の文字列を判別する条件式は以下のとおり。</p>
<h3>コード</h3>
<pre>
#!/bin/sh

if expr "$1" : '[0-9]*' > /dev/null ; then
  echo "数値です"
else
  echo "数値以外です"
fi
</pre>
<h3>実行結果</h3>
<pre>
$ ./if_numstr.sh 123
数値です
$ ./if_numstr.sh abc
数値以外です
</pre>
<h3>解説</h3>
<p>exprで正規表現を用いて数値を判定。exprは内部コード以外にも標準出力にも結果を返すので、不要なそれは/dev/nullへリダイレクトする。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/08/linux-bash.html" rel="bookmark" title="2011年8月8日">Linux: シェル(Bash)の機能の概要 &#8211; 復習のための覚書(前編)</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html" rel="bookmark" title="2011年2月13日">Shell Script: testコマンドによる条件判定 (数値、文字列)</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html" rel="bookmark" title="2011年2月6日">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a></li>
<li><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html" rel="bookmark" title="2011年1月30日">Shell Script: for文 &#8211; ワードリストを順に出力</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process-2.html" rel="bookmark" title="2008年1月10日">プロセスの監視＆自動復旧(簡易版)</a></li>
</ul>
<p><!-- Similar Posts took 5.514 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/08/bash-if-num-str.html">Bash: 数値と文字列の判別</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/08/bash-if-num-str.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSH サーバのインストールと公開鍵・秘密鍵の作成・設置</title>
		<link>http://www.yukun.info/blog/2011/04/openssh-server.html</link>
		<comments>http://www.yukun.info/blog/2011/04/openssh-server.html#comments</comments>
		<pubDate>Tue, 26 Apr 2011 15:00:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1901</guid>
		<description><![CDATA[この度、さくらVPS を利用し始めたので復習用に記録。 事前準備 先ずリモートコンソール上で以下の作業を実施。尚、コンソールはブラウザ上ではなく、Java Applet版の方が使い易いです。 既存のsshサーバをアンイン &#8230; <a href="http://www.yukun.info/blog/2011/04/openssh-server.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/04/openssh-server.html">OpenSSH サーバのインストールと公開鍵・秘密鍵の作成・設置</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>この度、さくらVPS を利用し始めたので復習用に記録。</p>
<h3>事前準備</h3>
<p>先ずリモートコンソール上で以下の作業を実施。尚、コンソールはブラウザ上ではなく、Java Applet版の方が使い易いです。</p>
<h4>既存のsshサーバをアンインストール</h4>
<pre>
# /etc/rc.d/init.d/sshd stop &larr; 停止
# yum -y remove openssh &larr; アンインストール
</pre>
<p><span id="more-1901"></span></p>
<h3>OpenSSHサーバのインストール</h3>
<p>最新版は以下のページで確認する。<br />
<a href="http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/">http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/</a></p>
<pre>
# yum -y install pam-devel
# wget http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-5.8p1.tar.gz &larr; 最新版をダウンロード
# tar zxvf openssh-5.8p1.tar.gz
# vi openssh-5.3p1/contrib/redhat/openssh.spec
</pre>
<p>openssh.specの修正項目は以下の通り。</p>
<pre>
＜前略＞
%define no_x11_askpass 0&rarr;1へ変更
%define no_gnome_askpass 0&rarr;1へ変更
＜中略＞
%configure \
	configure --without-zlib-version-check \ &larr;追記
＜後略＞
</pre>
<p>./openssh-5.8p1/contrib/redhat以外のディレクトリを削除し、RPMパッケージを作成。</p>
<pre>
# rm -rf openssh-5.8p1/contrib/aix/
# rm -rf openssh-5.8p1/contrib/hpux/
# rm -rf openssh-5.8p1/contrib/caldera/
# rm -rf openssh-5.8p1/contrib/suse/
# rm -rf openssh-5.8p1/contrib/cygwin/
# rm -rf openssh-5.8p1/contrib/solaris/
# tar czvf openssh-5.8p1.tar.gz openssh-5.8p1/
# rm -rf openssh-5.8p1
# rpmbuild -tb --clean openssh-5.8p1.tar.gz
</pre>
<p>以下のようなdependencies errorが発生した場合は必要なパッケージをインストールする。(ここではopenssl-develとkrb5-develを導入)</p>
<pre>
# rpmbuild -tb --clean openssh-5.8p1.tar.gz
error: Failed build dependencies:
        openssl-devel is needed by openssh-5.8p1-1.x86_64
        krb5-devel is needed by openssh-5.8p1-1.x86_64

# yum -y install openssl-devel krb5-devel &larr; 依存パッケージをインストール
# rpmbuild -tb --clean openssh-5.8p1.tar.gz &larr; 再実行
＜中略＞
Processing files: openssh-debuginfo-5.8p1-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/openssh-5.8p1-buildroot
Wrote: /usr/src/redhat/RPMS/x86_64/openssh-5.8p1-1.x86_64.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/openssh-clients-5.8p1-1.x86_64.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/openssh-server-5.8p1-1.x86_64.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/openssh-debuginfo-5.8p1-1.x86_64.rpm
＜後略＞
#
</pre>
<p>RPMパッケージの作成が完了したらそれらをインストールする。</p>
<pre>
# rpm -Uvh  /usr/src/redhat/RPMS/x86_64/openssh-5.8p1-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:openssh                ########################################### [100%]
# rpm -Uvh /usr/src/redhat/RPMS/x86_64/openssh-server-5.8p1-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:openssh-server         ########################################### [100%]
# rpm -Uvh /usr/src/redhat/RPMS/x86_64/openssh-clients-5.8p1-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:openssh-clients        ########################################### [100%]
# rm -f  /usr/src/redhat/RPMS/x86_64/openssh-* &larr; RPMを削除
# rm -f openssh-5.8p1.tar.gz &larr; ダウンロードファイルを削除
</pre>
<h4>sshサーバの起動</h4>
<pre>
# /etc/rc.d/init.d/sshd start &larr; 起動
# chkconfig sshd on &larr; 自動起動設定
# chkconfig --list sshd &larr; 2-5がonを確認
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
</pre>
<h3>公開鍵・秘密鍵を作成</h3>
<p>sshクライアントがPoderosaである場合の操作手順を一気に書くと、<br />
メニューバー[ツール]&rarr;SSH鍵作成ウィザード&rarr;初期値のまま、ユーザーのパスフレーズを入力し次へ&rarr;マウスをグリグリ動かして鍵生成&rarr;「秘密鍵を名前をつけて保存」と「OpenSSH形式で公開鍵を名前をつけて保存」のボタンで公開鍵・秘密鍵を作成(下図参照)。</p>
<p><a href="http://www.yukun.info/wp-content/uploads/ssh_key_gen.png"><img class="alignnone size-full wp-image-1908" title="ssh_key_gen" src="http://www.yukun.info/wp-content/uploads/ssh_key_gen.png" alt="ssh_key_gen" width="322" height="261" /></a></p>
<p>作成した公開鍵(文字列)を~/.ssh/authorized_keysに保存する。</p>
<pre>
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ vi ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
</pre>
<h3>sshサーバの設定</h3>
<p>設定ファイルを編集し鍵方式のみでのログインを許可する設定とする。</p>
<pre>
# vi /etc/ssh/sshd_config
</pre>
<p>変更要素、コメント解除行は以下のとおり。</p>
<pre>
Protocol 2 &larr; SSH2のみ
SyslogFacility AUTHPRIV &larr; ログファイルをCentOSデフォルトに
PermitRootLogin no &larr; rootログイン禁止
PasswordAuthentication no &larr; パスでのログイン禁止
PermitEmptyPasswords no &larr; パスなしログイン禁止
</pre>
<p>最後に設定を反映して完了。</p>
<pre>
# /etc/rc.d/init.d/sshd reload
Reloading sshd:                                            [  OK  ]
</pre>
<p>ちらっとアクセスログ(/var/log/secure)を確認したら、結構なBFAがありました。世のBotの監視は半端ないですね。公開後1時間足らずだというのに。。。sshdの待ち受けポートを変えようかな。</p>
<h3>追記(2011-05-04)：WinSCPでの秘密鍵設定</h3>
<p>WinSCPはPuTTY(*.ppk)の鍵しか対応していない為、Poderosaで作成した秘密鍵を使用するには、ppk形式に変換する必要がある。変換手順は、WinSCP付属アプリのPuTTY Key Generatorを起動し、メニュー「Conversions」→「Import key」で変換。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html" rel="bookmark" title="2011年12月6日">Linux: RedmineとSubversionのインストール・設定例</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/vmware-player-centos.html" rel="bookmark" title="2011年2月23日">VMware PlayerでCentOSをインストール</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/sshd-log-file.html" rel="bookmark" title="2008年6月24日">sshdのログファイルの確認方法</a></li>
<li><a href="http://www.yukun.info/blog/2009/06/white-list-fiters-spam-mail.html" rel="bookmark" title="2009年6月28日">携帯の迷惑メールフィルタのホワイトリスト（ドメイン）設定例</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/fedora-yum-install-gnome.html" rel="bookmark" title="2008年9月15日">FedoraにGUI環境GNOMEをyumでインストール</a></li>
</ul>
<p><!-- Similar Posts took 7.452 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/04/openssh-server.html">OpenSSH サーバのインストールと公開鍵・秘密鍵の作成・設置</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/04/openssh-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware PlayerでCentOSをインストール</title>
		<link>http://www.yukun.info/blog/2011/02/vmware-player-centos.html</link>
		<comments>http://www.yukun.info/blog/2011/02/vmware-player-centos.html#comments</comments>
		<pubDate>Wed, 23 Feb 2011 14:50:05 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Setting]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1833</guid>
		<description><![CDATA[目的 Windows7上のVMware Playerの仮想マシンにCentOSをインストールする。 準備 ダウンロードするものは下記の通り。 VMware Player ：簡単に仮想マシンを実行できる無償ソフトウェア 尚 &#8230; <a href="http://www.yukun.info/blog/2011/02/vmware-player-centos.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/02/vmware-player-centos.html">VMware PlayerでCentOSをインストール</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>目的</h3>
<p>Windows7上のVMware Playerの仮想マシンにCentOSをインストールする。</p>
<h3>準備</h3>
<p>ダウンロードするものは下記の通り。</p>
<p><span id="more-1833"></span></p>
<ol>
<li><a href="http://www.vmware.com/jp/products/player/">VMware Player ：簡単に仮想マシンを実行できる無償ソフトウェア</a><br />
尚、ダウンロードには①苗字②名前③メールアドレスの入力が必要。ダウンロードファイルサイズは100MB程度で、インストールはウィザードに沿って進め、最後にPCの再起動をする。
</li>
<li><a href="http://www.centos.org/">www.centos.org &#8211; The Community ENTerprise Operating System</a><br />
CentOSはDownloadページ先のミラーサイトから「CentOS-<em>5.5</em>-i386-bin-DVD.<strong>torrent</strong>」をダウンロードしtorrentクライアントソフトを用いてDVD ISOイメージをダウンロードする。尚、torrentクライアントソフトは<a href="http://www.utorrent.com/">µTorrent</a>がオススメ。
</li>
</ol>
<h3>仮想マシン・CentOSの導入手順</h3>
<p>ウィザードに沿って導入が可能。</p>
<p>1. VMwareの初期画面から「新規仮想マシンの作成」を選択。<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_main_window.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_main_window-e1298471485531.png" alt="vmware_main_window" title="vmware_main_window" width="400" height="340" class="alignnone size-full wp-image-1836" /></a></p>
<p>2. インストーラー ディスク イメージ ファイルに上でダウンロードしたCentOSのisoイメージのファイルパスを入力。<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm01.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm01.png" alt="" title="vmware_makevm01" width="513" height="379" class="alignnone size-full wp-image-1838" /></a></p>
<p>3. ユーザーID名とそのパスワード、及びrootパスワードを入力<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm02.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm02.png" alt="" title="vmware_makevm02" width="513" height="379" class="alignnone size-full wp-image-1840" /></a></p>
<p>4. 仮想マシン設定ファイルの決定(デフォルト)<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm03.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm03.png" alt="" title="vmware_makevm03" width="513" height="379" class="alignnone size-full wp-image-1841" /></a></p>
<p>5. ディスク容量の決定<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm04.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm04.png" alt="" title="vmware_makevm04" width="513" height="379" class="alignnone size-full wp-image-1842" /></a></p>
<p>6. 仮想マシンのハードウェアの設定<br />
下図の「ハードウェアをカスタマイズ」をクリックすると仮想マシンのメモリやCPU数を設定可能。<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm05.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm05.png" alt="vmware_makevm05" title="vmware_makevm05" width="513" height="379" class="alignnone size-full wp-image-1843" /></a></p>
<p>メモリの割当(下図では1GB)<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_makevm05_1.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_makevm05_1-e1298472579686.png" alt="vmware_makevm05_1" title="vmware_makevm05_1" width="400" height="332" class="alignnone size-full wp-image-1844" /></a></p>
<p>完了をクリックするとCentOSのインストールが開始。</p>
<p>7. インストール経過<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_centos01.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_centos01-e1298472185131.png" alt="vmware_centos01" title="vmware_centos01" width="400" height="353" class="alignnone size-full wp-image-1845" /></a></p>
<p>8. インストール完了後は自動で立ち上がる<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_centos03.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_centos03-e1298472229220.png" alt="vmware_centos03" title="vmware_centos03" width="400" height="251" class="alignnone size-full wp-image-1846" /></a></p>
<p>9. ログイン画面<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_centos04.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_centos04-e1298472339151.png" alt="vmware_centos04" title="vmware_centos04" width="400" height="262" class="alignnone size-full wp-image-1847" /></a></p>
<p>10. Loginnameに手順3で入力したユーザー名 or 「root」を入力してログイン<br />
<a href="http://www.yukun.info/wp-content/uploads/vmware_centos05.png"><img src="http://www.yukun.info/wp-content/uploads/vmware_centos05-e1298472437846.png" alt="vmware_centos05" title="vmware_centos05" width="400" height="323" class="alignnone size-full wp-image-1848" /></a></p>
<p>以上、何か不明な点があればコメントにてお知らせ下さい。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/01/cygwin-cron.html" rel="bookmark" title="2008年1月8日">Cygwinでcronをインストール</a></li>
<li><a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html" rel="bookmark" title="2011年12月6日">Linux: RedmineとSubversionのインストール・設定例</a></li>
<li><a href="http://www.yukun.info/blog/2010/03/java-install-sen-windows.html" rel="bookmark" title="2010年3月25日">Java: 形態素解析Senをインストール(Windows編)</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/fedora-yum-install-gnome.html" rel="bookmark" title="2008年9月15日">FedoraにGUI環境GNOMEをyumでインストール</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/install-lxml.html" rel="bookmark" title="2008年6月13日">Python: lxmlのインストール方法</a></li>
</ul>
<p><!-- Similar Posts took 8.345 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/02/vmware-player-centos.html">VMware PlayerでCentOSをインストール</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/02/vmware-player-centos.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script: testコマンドによる条件判定 (数値、文字列)</title>
		<link>http://www.yukun.info/blog/2011/02/shell-script-test.html</link>
		<comments>http://www.yukun.info/blog/2011/02/shell-script-test.html#comments</comments>
		<pubDate>Sun, 13 Feb 2011 07:00:56 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1798</guid>
		<description><![CDATA[上表はshの組み込み、かつ外部コマンドでもあるtestコマンドの判定表。testコマンドは与えられた条件式に対して、終了コードに真「0」、偽「1」を返す。他のプログラミング言語の条件判定とは真偽の値の意味が逆なので違和感 &#8230; <a href="http://www.yukun.info/blog/2011/02/shell-script-test.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html">Shell Script: testコマンドによる条件判定 (数値、文字列)</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.yukun.info/wp-content/uploads/test_command.gif"><img src="http://www.yukun.info/wp-content/uploads/test_command.gif" alt="test_command" title="test_command" width="462" height="219" class="alignnone size-full wp-image-1808" /></a></p>
<p>上表はshの組み込み、かつ外部コマンドでもあるtestコマンドの判定表。testコマンドは与えられた条件式に対して、終了コードに<strong>真「0」</strong>、<strong>偽「1」</strong>を返す。他のプログラミング言語の条件判定とは真偽の値の意味が逆なので違和感を覚えるが、例えばC言語のmainのreturn (システムへのreturn)は正常では0、異常では1を返す例と同様と考えるとしっくりくるかな。。</p>
<p><span id="more-1798"></span></p>
<pre>
$ test 10 -gt 20
$ echo $?
1
$ test 10 -lt 20
$ echo $?
0
</pre>
<p>以下のシェルスクリプトはtestコマンドを用いた条件判定のサンプルとなる。</p>
<h3>数値の比較</h3>
<h4>スクリプトコード</h4>
<pre>
#!/bin/sh

if test $1 -eq $2
then
	echo &quot;($1)  = ($2)&quot;
else
	echo &quot;($1) != ($2)&quot;
fi

if [ $1 -le $2 ]
then
	echo &quot;($1) &lt;= ($2)&quot;
else
	echo &quot;($1) &gt;  ($2)&quot;
fi
</pre>
<p>尚、testコマンドは[ <em>条件式</em> ]でも記述できる。</p>
<h4>実行結果</h4>
<pre>
$ sh test01.sh 10 10
(10)  = (10)
(10) &lt;= (10)
$ sh test01.sh 10 20
(10) != (20)
(10) &lt;= (20)
$ sh test01.sh 10 5
(10) != (5)
(10) &gt;  (5)
</pre>
<h3>文字列の比較</h3>
<h4>スクリプトコード</h4>
<pre>
#!/bin/sh
if [ &quot;$1&quot; = &quot;$2&quot; ]
then
	echo &quot;($1)  = ($2)&quot;
else
	echo &quot;($1) != ($2)&quot;
fi

if [ &quot;$3&quot; != &quot;&quot; ]
then
	echo &quot;\$3 is not null. It&#039;s &lt;$3&gt;.&quot;
fi
</pre>
<h4>実行結果</h4>
<pre>
$ sh test02.sh hello world shell
(hello) != (world)
$3 is not null. It&#039;s &lt;shell&gt;.

$ sh test02.sh hello hello
(hello)  = (hello)
</pre>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html" rel="bookmark" title="2011年1月30日">Shell Script: for文 &#8211; ワードリストを順に出力</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html" rel="bookmark" title="2011年2月6日">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process-2.html" rel="bookmark" title="2008年1月10日">プロセスの監視＆自動復旧(簡易版)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process.html" rel="bookmark" title="2008年1月7日">シェルスクリプトでプロセスを監視し自動実行＆自動kill</a></li>
<li><a href="http://www.yukun.info/blog/2011/08/bash-if-num-str.html" rel="bookmark" title="2011年8月5日">Bash: 数値と文字列の判別</a></li>
</ul>
<p><!-- Similar Posts took 9.007 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html">Shell Script: testコマンドによる条件判定 (数値、文字列)</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/02/shell-script-test.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion: コトハジメ</title>
		<link>http://www.yukun.info/blog/2011/02/subversion-intro.html</link>
		<comments>http://www.yukun.info/blog/2011/02/subversion-intro.html#comments</comments>
		<pubDate>Mon, 07 Feb 2011 13:00:59 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1345</guid>
		<description><![CDATA[以前Mac bookでSubversionを使用したときのメモ(備忘録用)。 (今後使い込んだ際に改めて書きなおそうかな。。) リポジトリの作成 データする格納ディレクトリをSubversionに登録する。 svnadm &#8230; <a href="http://www.yukun.info/blog/2011/02/subversion-intro.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/02/subversion-intro.html">Subversion: コトハジメ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>以前Mac bookでSubversionを使用したときのメモ(備忘録用)。<br />
(今後使い込んだ際に改めて書きなおそうかな。。)</p>
<h3>リポジトリの作成</h3>
<p>データする格納ディレクトリをSubversionに登録する。</p>
<p><span id="more-1345"></span></p>
<blockquote><p>
svnadmin create ＜ディレクトリのパス名＞
</p></blockquote>
<pre>
mkdir /Users/yukun/svn-repos
svnadmin create /Users/yukun/svn-repos
</pre>
<h3>準備用のディレクトリを作成</h3>
<ul>
<li>インポートするフィアルが存在するディレクトリに移動。</li>
<li>リポジトリにプロジェクトのファイルをインポート（リポジトリに追加する）する。</li>
<li>Firstrunプロジェクトとする。</li>
<li>-mオプションで任意のメッセージを関連付けられる。</li>
</ul>
<pre>
mkdir /Users/yukun/tmp
cd tmp
</pre>
<pre>
tmp> svn import -m "imoprting firstrun project" . file:///Users/yukun/svn-repos/firstrun/trunk
Adding         Number.txt
Adding         Day.txt

Committed revision 1.
</pre>
<h4>インポートの一般式</h4>
<blockquote><p>
svn import -m &#8220;＜コメント＞&#8221; ＜ファイルが入っているディレクトリのパス＞ ＜リポジトリのパス＞
</p></blockquote>
<p>カレントディレクトリ内のフィアルをインポートしたことになる。</p>
<pre>
$ mkdir /Users/yukun/work
作業ディレクトリを作成
$ cd work
$ mkdir firstrun
</pre>
<h3>チェックアウト</h3>
<p>リポジトリからローカルに最新の変更を受け取る。</p>
<pre>
work> svn co file:///Users/yukun/svn-repos/firstrun/trunk firstrun
A    firstrun/Number.txt
A    firstrun/Day.txt
Checked out revision 1.
</pre>
<h4>チェックアウトの一般式</h4>
<blockquote><p>
$ svn co ＜リポジトリのパス＞ ＜コピー先ディレクトリのパス＞
</p></blockquote>
<p>プロジェクトがローカルで変更が行われたか否かを確認。</p>
<pre>
firstrun>  svn status Day.txt
M      Day.txt
</pre>
<p>Mはローカルで変更されていて、その変更がリポジトリにコミットされていない。</p>
<p>プロジェクト内のファイルの差分を確認。</p>
<pre>
svn diff Day.txt
Index: Day.txt
===================================================================
--- Day.txt	(revision 1)
+++ Day.txt	(working copy)
@@ -2,4 +2,6 @@
 tuesday
 wednesday
 thrusday
-friday
 No newline at end of file
+friday
+saturday
+sunday
 No newline at end of file
</pre>
<h3>リポジトリの更新（コミット）</h3>
<pre>
firstrun> svn commit -m "Client wants us to work on weekends"weekends"
Sending        Day.txt
Transmitting file data .
Committed revision 2.
</pre>
<p>リビジョン番号は変更したファイル数にかかわらずリポジトリ全体に及ぶ</p>
<h4>コミットの一般式</h4>
<p>作業ディレクトリ内で</p>
<blockquote><p>
firstrun> svn commit -m &#8220;＜コメント＞&#8221;
</p></blockquote>
<p>リポジトリが実際に更新されたかどうか確認する。</p>
<pre>
firstrun> svn log Day.txt
------------------------------------------------------------------------
r2 | yukun | 2008-12-23 17:28:42 +0900 (火, 23 12 2008) | 1 line

Client wants us to work on weekends
------------------------------------------------------------------------
r1 | yukun | 2008-12-23 16:51:27 +0900 (火, 23 12 2008) | 1 line

imoprting firstrun project
------------------------------------------------------------------------
</pre>
<p>変更の詳細を出力。</p>
<pre>
firstrun> svn log --verbose Day.txt
------------------------------------------------------------------------
r2 | yukun | 2008-12-23 17:28:42 +0900 (火, 23 12 2008) | 1 line
Changed paths:
   M /firstrun/trunk/Day.txt

Client wants us to work on weekends
------------------------------------------------------------------------
r1 | yukun | 2008-12-23 16:51:27 +0900 (火, 23 12 2008) | 1 line
Changed paths:
   A /firstrun
   A /firstrun/trunk
   A /firstrun/trunk/Day.txt
   A /firstrun/trunk/Number.txt

imoprting firstrun project
------------------------------------------------------------------------
</pre>
<p>$ svn log のみだと最新の変更は出てこない。<br />
また、作業ディレクトリ以外でコマンドを実行すると、</p>
<pre>
work> svn log
svn: '.' is not a working copy
</pre>
<p>のようにエラーとなる。</p>
<h3>競合の発生</h3>
<p>2人目のユーザの作業ディレクトリをfirstrun02とする。</p>
<pre>
svn co file:///Users/yukun/svn-repos/firstrun/trunk firstrun02
A    firstrun02/Number.txt
A    firstrun02/Day.txt
Checked out revision 2.

firstrun> svn commit -m "Customer wants more numbers"
Sending        Number.txt
Transmitting file data .
Committed revision 3.
</pre>
<p>作業ディレクトリのファイルにチェックアウトしたものより新しいバージョンがあるか否かを確認。</p>
<pre>
firstrun02> svn status --show-updates
       *        2   Number.txt
Status against revision:      3
firstrun02> svn status -u
       *        2   Number.txt
Status against revision:      3
</pre>
<p>*はリポジトリ内に更新済みのものが存在するかどうか、<br />
すなわちローカルにあるフィアルは古いですよ、ということ。</p>
<p>ローカルのコピーとリポジトリ内の最新のリビジョンを比較するには、</p>
<pre>
firstrun02> svn diff -rHEAD Number.txt
ndex: Number.txt
===================================================================
--- Number.txt	(revision 3)
+++ Number.txt	(working copy)
@@ -2,6 +2,4 @@
 one
 two
 three
-four
-five
-six
 No newline at end of file
+four
 No newline at end of file
</pre>
<p>普通のdiffではチェックアウトされたリビジョン、ここではr2としか比較しないので、変更点を検出できない。</p>
<p>作業ディレクトリのファイルを更新して最新のリビジョンにマージするには、</p>
<pre>
firstrun02> svn update
U    Number.txt
Updated to revision 3.
</pre>
<p>Uはフィアルが更新されたことを示している。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/12/linux-redmine-subversion-install.html" rel="bookmark" title="2011年12月6日">Linux: RedmineとSubversionのインストール・設定例</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/linux-users.html" rel="bookmark" title="2008年6月26日">ユーザー管理に関するLinuxコマンド</a></li>
<li><a href="http://www.yukun.info/blog/2009/02/netbeans-subversion-import-error.html" rel="bookmark" title="2009年2月12日">NetBeans から Subversion でコミットをする際のエラーの解決法の一例</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/how-to-write-apache-conf.html" rel="bookmark" title="2008年12月25日">Apacheでよく使うコマンドと設定項目</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/r-set-work-directory.html" rel="bookmark" title="2008年9月3日">Rで統計: 作業ディレクトリの設定と確認 &#8211; setwd()、getwd()関数</a></li>
</ul>
<p><!-- Similar Posts took 8.683 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/02/subversion-intro.html">Subversion: コトハジメ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/02/subversion-intro.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</title>
		<link>http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html</link>
		<comments>http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html#comments</comments>
		<pubDate>Sun, 06 Feb 2011 11:00:10 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1754</guid>
		<description><![CDATA[以下のシェルスクリプトはfor文のワードリストに文字列変数を使用したもの。文字列はスペース区切でパラメータ変数に格納されloopする。また、ワードリストにバッククォートで括ったコマンドを指定すると、そのコマンドの実行結果 &#8230; <a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>以下のシェルスクリプトはfor文のワードリストに文字列変数を使用したもの。文字列はスペース区切でパラメータ変数に格納されloopする。また、ワードリストにバッククォートで括ったコマンドを指定すると、そのコマンドの実行結果がパラメータ変数に渡される。</p>
<pre>
#!/bin/sh

VARS="1 2 3 four five"
for VAR in $VARS
do
	echo $VAR
done

echo ""
for LIST in `date`
do
	echo $LIST
done
</pre>
<p><span id="more-1754"></span></p>
<p>実行結果は下記の通り。</p>
<pre>
$ sh for_var.sh
1
2
3
four
five

2011年
2月
6日
日曜日
12:31:09
JST
</pre>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html" rel="bookmark" title="2011年1月30日">Shell Script: for文 &#8211; ワードリストを順に出力</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html" rel="bookmark" title="2011年2月13日">Shell Script: testコマンドによる条件判定 (数値、文字列)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process-2.html" rel="bookmark" title="2008年1月10日">プロセスの監視＆自動復旧(簡易版)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process.html" rel="bookmark" title="2008年1月7日">シェルスクリプトでプロセスを監視し自動実行＆自動kill</a></li>
<li><a href="http://www.yukun.info/blog/2011/08/bash-if-num-str.html" rel="bookmark" title="2011年8月5日">Bash: 数値と文字列の判別</a></li>
</ul>
<p><!-- Similar Posts took 9.402 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script: for文 &#8211; ワードリストを順に出力</title>
		<link>http://www.yukun.info/blog/2011/01/shell-for-wordlist.html</link>
		<comments>http://www.yukun.info/blog/2011/01/shell-for-wordlist.html#comments</comments>
		<pubDate>Sun, 30 Jan 2011 13:30:39 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1739</guid>
		<description><![CDATA[シェルスクリプトのfor文の一般式は下記の通り。 for パラメータ変数 in ワードリスト do コマンド done ワードリストの要素をパラメータ変数に代入しdo～done間をワードリストの要素分ループする。 以下の &#8230; <a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html">Shell Script: for文 &#8211; ワードリストを順に出力</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>シェルスクリプトのfor文の一般式は下記の通り。</p>
<pre>
for パラメータ変数 in ワードリスト
do
	コマンド
done
</pre>
<p>ワードリストの要素をパラメータ変数に代入しdo～done間をワードリストの要素分ループする。</p>
<p><span id="more-1739"></span></p>
<p>以下のシェルスクリプトは数値の羅列を出力するもの。</p>
<pre>
#!/bin/sh

for i in 0 1 2 3 4 5 6 7 8 9
do
	echo "\$i = $i,"
done
</pre>
<p>実行結果は下記の通り。</p>
<pre>
$ sh for_wordlist.sh
$i = 0,
$i = 1,
$i = 2,
$i = 3,
$i = 4,
$i = 5,
$i = 6,
$i = 7,
$i = 8,
$i = 9,
</pre>
<p>また、ワードリストを文字列にしたスクリプトを以下に示す。</p>
<pre>
#!/bin/sh

for VAR in 'Dead or alive.' Pardon? "You're d..."
do
	echo $VAR
done
</pre>
<p>実行結果は下記の通り。</p>
<pre>
$ sh for_wordlist_str.sh
Dead or alive.
Pardon?
You're d...
</pre>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2011/02/shell-for-wordlist-command.html" rel="bookmark" title="2011年2月6日">Shell Script: for文 &#8211; ワードリストに変数、コマンドを使用</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process-2.html" rel="bookmark" title="2008年1月10日">プロセスの監視＆自動復旧(簡易版)</a></li>
<li><a href="http://www.yukun.info/blog/2011/02/shell-script-test.html" rel="bookmark" title="2011年2月13日">Shell Script: testコマンドによる条件判定 (数値、文字列)</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/shell-script-kill-process.html" rel="bookmark" title="2008年1月7日">シェルスクリプトでプロセスを監視し自動実行＆自動kill</a></li>
<li><a href="http://www.yukun.info/blog/2011/08/linux-bash.html" rel="bookmark" title="2011年8月8日">Linux: シェル(Bash)の機能の概要 &#8211; 復習のための覚書(前編)</a></li>
</ul>
<p><!-- Similar Posts took 8.699 ms --></p>
<p><a href="http://www.yukun.info/blog/2011/01/shell-for-wordlist.html">Shell Script: for文 &#8211; ワードリストを順に出力</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2011/01/shell-for-wordlist.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

