LIPCレベル1試験から学んだ事(Part3)

  • ファイルの個数やサイズ、メモリ使用量を制限(ulimit)

メモリ割り当て不可、など、とりあえず何でもいいからコマンドを失敗させたい時とかのテストに使えるかも。

user@ubuntu:~$ ulimit -a 
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3780
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3780
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
user@ubuntu:~$ 
user@ubuntu:~$ ulimit -v 1200
user@ubuntu:~$ 
user@ubuntu:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3780
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3780
virtual memory          (kbytes, -v) 1200
file locks                      (-x) unlimited
user@ubuntu:~$ 
user@ubuntu:~$ vi; echo $?
Segmentation fault
139
user@ubuntu:~$ 
user@ubuntu:~$ cat a
あいうえお
user@ubuntu:~$ nkf -g a
UTF-8
user@ubuntu:~$ cat a |iconv -f UTF-8 -t Shift_JIS |nkf -g
Shift_JIS
user@ubuntu:~$ 

LIPCレベル1試験から学んだ事(Part1)

user@ubuntu:~$ uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
user@ubuntu:~$ 

普段 echo $[変数名] しか使わないので、今後は env や printenv も活用しようと思った次第。

user@ubuntu:~$ env |grep PATH
user@ubuntu:~$ printenv PATH
user@ubuntu:~$ echo $PATH
  • リダイレクトによるファイルの上書き防止(set -o noclobber, set -C)

自分でシェルスクリプトを書く時は、先頭にこのオプション入れてもいいかも、と思う。

user@ubuntu:~$ echo "xxx" >/tmp/tmpfile.txt
user@ubuntu:~$ echo "xxx" >/tmp/tmpfile.txt
user@ubuntu:~$ set -o noclobber
user@ubuntu:~$ echo "xxx" >/tmp/tmpfile.txt
-bash: /tmp/tmpfile.txt: cannot overwrite existing file
user@ubuntu:~$ set +o noclobber
user@ubuntu:~$ echo "xxx" >/tmp/tmpfile.txt
user@ubuntu:~$ set -C 
user@ubuntu:~$ echo "xxx" >/tmp/tmpfile.txt
-bash: /tmp/tmpfile.txt: cannot overwrite existing file
user@ubuntu:~$ 
  • ファイルを変更できないようにする(chattr)

こんなコマンドがあるとは知らなかった。
rmなどのコマンドが失敗した場合のエラーハンドリングのテスト時などに使えそう。

user@ubuntu:~$ touch testfile
user@ubuntu:~$ lsattr testfile 
-------------e-- testfile
user@ubuntu:~$ sudo chattr +i testfile 
[sudo] password for user: 
user@ubuntu:~$ lsattr testfile 
----i--------e-- testfile
user@ubuntu:~$ ls -l testfile 
-rw-rw-r-- 1 user user 0 May 24 07:00 testfile
user@ubuntu:~$ rm testfile 
rm: remove write-protected regular empty file ‘testfile’? y
rm: cannot remove ‘testfile’: Operation not permitted
user@ubuntu:~$ sudo rm -f testfile 
rm: cannot remove ‘testfile’: Operation not permitted
user@ubuntu:~$ sudo chattr -i testfile 
user@ubuntu:~$ lsattr testfile 
-------------e-- testfile
user@ubuntu:~$ rm testfile 
user@ubuntu:~$ ls -l testfile
ls: cannot access testfile: No such file or directory
user@ubuntu:~$ 
  • grepした結果、ヒットしたファイル名だけを表示

今まで grep -rn foobar * |cut -d':' -f1 |sort |uniq とかで乗り切ってたので、-l オプションがある grep は非常に助かる

user@ubuntu:~/r$ grep -l AppleWebKit *01.csv
001-2013-01.csv
001-2014-01.csv
001-2015-01.csv
user@ubuntu:~/r$ 

ホームディレクトリ以外の .vimrc を常に読み込む

同一ユーザを複数人で共有していて、ホームディレクトリに自分専用の .vimrc を置けない場合は、環境変数 VIMINIT または EXINIT を設定して自分専用の .vimrc を読み込めばよい。

ubuntu@ubuntu-14:~/vim$ set |grep VIM
VIMINIT='so ~/vim/.vimrc'
ubuntu@ubuntu-14:~/vim$ cat ~/vim/.vimrc
set nu
set ic
set tabstop=4
set shiftwidth=4
set autoindent
"エンコード優先順位指定
set fileencodings=cp932,euc-jp,utf-8,iso-2022-jp,default,latin
"ステータスラインを常に表示
set laststatus=2
"ステータスラインに文字コードと改行文字を表示する
set statusline=%<%f\ %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%l,%c%V%8P
ubuntu@ubuntu-14:~/vim$ 

バックグラウンドで実行した処理が全て完了するまで待つ

$ cat 20150906.sh 
#!/bin/bash --norc

# 引数で指定された秒数バックグラウンドでSLEEPする
function _sleep()
{
        sleep $1 &
        # バックグラウンドで実行されたプロセスのPIDを設定
        PID=$!
        echo "sleep $1 seconds; pid=${PID}"
}

# 10〜20秒バックグラウンドでSLEEPする
for i in `seq 10 20` ; do
        _sleep $i
        i=`expr $i + 1`
done

echo "---"

# 全JOBの終了を待つ(1)
#for job in `jobs -p`; do
#       echo "waiting: $job"
#       sleep 1
#done

# バックグラウンドで実行中のプロセス一覧を表示
# "+"がカレント・ジョブを表し,"-"が前のジョブを表す
# -l オプションでPIDも表示する
jobs -l

# 全JOBの終了を待つ(2)
# バックグラウンドプロセスが全て終了するまでWAITする
wait

exit 0
$ 
$ ./20150906.sh 
sleep 10 seconds; pid=4576
sleep 11 seconds; pid=4578
sleep 12 seconds; pid=4580
sleep 13 seconds; pid=4582
sleep 14 seconds; pid=4584
sleep 15 seconds; pid=4586
sleep 16 seconds; pid=4588
sleep 17 seconds; pid=4590
sleep 18 seconds; pid=4592
sleep 19 seconds; pid=4594
sleep 20 seconds; pid=4596
---
[1]   4576 実行中               sleep $1 &
[2]   4578 実行中               sleep $1 &
[3]   4580 実行中               sleep $1 &
[4]   4582 実行中               sleep $1 &
[5]   4584 実行中               sleep $1 &
[6]   4586 実行中               sleep $1 &
[7]   4588 実行中               sleep $1 &
[8]   4590 実行中               sleep $1 &
[9]   4592 実行中               sleep $1 &
[10]-  4594 実行中               sleep $1 &
[11]+  4596 実行中               sleep $1 &
$ 

ファイルを1行1行を読みこんで処理する

$ cat foo.sh 
#!/bin/bash --norc

cat infile |
        grep -v "^[[:space:]]*$" |   # 空行をSKIP
        grep -v "^[[:space:]]*#" |   # #で始まる行をSKIP
while read LINE
do
        LINE=`echo ${LINE} |sed 's/[[:space:]]*#.*//g'`    # #以降はコメント扱い
        echo ":${LINE}:"
done

exit 0
$ 
$ cat infile 
## comment
line1 #1
 line2 #2
        line3 #3
         line4#4
         line5 #5

 # comment
        # comment
         # comment
$ 
$ ./foo.sh 
:line1:
:line2:
:line3:
:line4:
:line5:
$ 

WinSCPでLinux上のファイルを自動でWindowsにバックアップする

LinuxサーバのファイルをWindowsにバックアップする場合、WinSCPをバッチモードで実行するのが手っ取り早い。WinSCP用のスクリプトファイルとWindowsのバッチファイルの2種類用意すれば良い。

WinSCP用のスクリプトファイル(rsync-ubuntu-14.04-server-amd64.txt)

option batch abort
option confirm off
#サーバに接続
open scp://ubuntu:ubuntu@192.168.233.101

#WinSCPのsynchronizeコマンドを発行
#下記はサーバーのhomeディレクトリをWindowsにコピーする場合の例
synchronize local -delete C:\xxx\home /home/ubuntu
exit

上記のスクリプトを実行するためのWindowsバッチファイル

C:\winscp572\WinSCP.com /script=rsync-ubuntu-14.04-server-amd64.txt
pause

WinSCPのコマンドリファレンス
http://sourceforge.jp/projects/winscp/wiki/script_commands

UNIXコマンドのソースを見る方法

ubuntu@ubuntu-14:~$ uname -a
Linux ubuntu-14 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

## 前準備
#apt-fileをインストールする
ubuntu@ubuntu-14:~$ sudo apt-get install apt-file
#データベースの最新化
ubuntu@ubuntu-14:~$ apt-file update

## apt-getを使ってソースを探す
#例として/bin/echoのソースを探す
ubuntu@ubuntu-14:~$ apt-file search /bin/echo
9base: /usr/lib/plan9/bin/echo
alsa-tools-gui: /usr/bin/echomixer
coreutils: /bin/echo
dcmtk: /usr/bin/echoscu
echoping: /usr/bin/echoping
libbonobo2-bin: /usr/bin/echo-client-2
supervisor: /usr/bin/echo_supervisord_conf

#/bin/echoが含まれるcoreutilsのソースコードを取得する
ubuntu@ubuntu-14:~$ apt-get source coreutils

#ソースコードはカレントディレクトリに展開される
ubuntu@ubuntu-14:~$ ls -l ./coreutils-8.21/src/echo.c 
-rw-rw-r-- 1 ubuntu ubuntu 7630  131  2013 ./coreutils-8.21/src/echo.c

CVSのインストール

## cvsのインストール
ubuntu@ubuntu-14:~$ sudo apt-get install cvs

## xinetdのインストール
ubuntu@ubuntu-14:~$ sudo apt-get install xinetd

## リポジトリの作成
ubuntu@ubuntu-14:~$ cvs -d /home/ubuntu/cvsroot init

## xinetdの起動設定
ubuntu@ubuntu-14:~$ cat /etc/xinetd.d/cvspserver
service cvspserver
 {
 port = 2401
 socket_type = stream
 protocol = tcp
 user = root
 wait = no
 type = UNLISTED
 server = /usr/bin/cvs
 server_args = -f --allow-root /home/ubuntu/cvsroot pserver
 disable = no
 }

## cvs用のOSユーザ作成
#ユーザ作成
ubuntu@ubuntu-14:/etc/xinetd.d$ sudo useradd cvsuser

## リポジトリの所有権変更
ubuntu@ubuntu-14:~$ sudo chown -R cvsuser.cvsuser /home/ubuntu/cvsroot/

## cvs利用ユーザの作成
#パスワード生成ツールのインストール
ubuntu@ubuntu-14:~/cvswork$ sudo apt-get install whois

#パスワード生成(htpasswdで生成したパスワードではログインできなかったのでmkpasswdで生成する)
ubuntu@ubuntu-14:~/cvswork$ mkpasswd cvsuser
urCo8tVK9tsXI

#パスワードファイルに書き込み
ubuntu@ubuntu-14:~/cvswork$ ls -l /home/ubuntu/cvsroot/CVSROOT/passwd 
-rw-r--r-- 1 cvsuser cvsuser 30  422 00:01 /home/ubuntu/cvsroot/CVSROOT/passwd

ubuntu@ubuntu-14:~/cvswork$ cat /home/ubuntu/cvsroot/CVSROOT/passwd
cvsuser:urCo8tVK9tsXI:cvsuser

## xinetdの再起動とサービス起動確認
#再起動
ubuntu@ubuntu-14:/etc/xinetd.d$ sudo /etc/init.d/xinetd restart

#サービス起動確認
ubuntu@ubuntu-14:/etc/xinetd.d$ sudo netstat -tap |grep cvs
tcp        0      0 *:cvspserver            *:*                     LISTEN      3376/xinetd     

## cvsへの接続確認
#環境変数設定(:pserver:ユーザ名:パスワード@ホスト名:リポジトリのパス)
ubuntu@ubuntu-14:~/cvswork$ CVSROOT=:pserver:cvsuser:cvsuser@localhost:/home/ubuntu/cvsroot; export CVSROOT;

#ログイン
ubuntu@ubuntu-14:~/cvswork$ cvs login
Logging in to :pserver:cvsuser@localhost:2401/home/ubuntu/cvsroot

※参考
インストールに関して
http://www.itnotes.eu/?p=358
http://a23187.yorozuyah.com/blog/?p=279

パスワードの生成について
http://docstore.mik.ua/orelly/other/cvs/cvs-CHP-8-SECT-7.htm

ssh-agentの注意点

ssh-agentを一度起動すると、ログアウトしてもプロセスが残ったままになるので要注意。

########################################################################
## 実証 : ssh-agentを一度起動するとログアウトしてもプロセスは残ったまま
########################################################################
## 検証環境
ubuntu1410@ubuntu1410:~$ uname -a
Linux ubuntu1410 3.16.0-23-generic #31-Ubuntu SMP Tue Oct 21 17:56:17 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

## ログインしてssh-agentを起動する、その後ログアウト
ubuntu1410@ubuntu1410:~$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-rHUra7orSbjX/agent.1503; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1504; export SSH_AGENT_PID;
echo Agent pid 1504;
ubuntu1410@ubuntu1410:~$ ps -aef |grep ssh-agent
ubuntu1+  1504     1  0 23:26 ?        00:00:00 ssh-agent
ubuntu1+  1506  1470  0 23:26 pts/1    00:00:00 grep --color=auto ssh-agent
ubuntu1410@ubuntu1410:~$ exit

## 再ログインしてプロセスを調べると、前回ログイン時のプロセスが残っている
ubuntu1410@ubuntu1410:~$ ps -aef |grep ssh-agent
ubuntu1+  1504     1  0 23:26 ?        00:00:00 ssh-agent
ubuntu1+  1578  1561  0 23:27 pts/1    00:00:00 grep --color=auto ssh-agent

# /tmpの下にもファイル(ソケット)が残ったままの状態
ubuntu1410@ubuntu1410:~$ ls -lR /tmp/
/tmp/:
合計 4
drwx------ 2 ubuntu1410 ubuntu1410 4096  420 23:26 ssh-rHUra7orSbjX

/tmp/ssh-rHUra7orSbjX:
合計 0
srw------- 1 ubuntu1410 ubuntu1410 0  420 23:26 agent.1503

プロセスをkillするには単純にkillコマンドでも良いが、せっかくなのでssh-agentでkillしてみる。

## ssh-agentのプロセスをkillする
# まずは環境変数SSH_AGENT_PIDを設定する(ssh-agentを起動した時のコンソール出力参照)
ubuntu1410@ubuntu1410:~$ SSH_AGENT_PID=1504; export SSH_AGENT_PID;
# agentをkillする
ubuntu1410@ubuntu1410:~$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 1504 killed;

# プロセスが消えた
ubuntu1410@ubuntu1410:~$ ps -aef |grep ssh-agent
ubuntu1+  1655  1561  0 23:41 pts/1    00:00:00 grep --color=auto ssh-agent
# /tmpにあったファイル(ソケット)も消えた
ubuntu1410@ubuntu1410:~$ ls -lR /tmp/
/tmp/:
合計 0

残っているプロセスを再利用するなら、環境変数を設定すれば良い。

## 残っているssh-agentのプロセスを再利用するには
## 環境変数 SSH_AGENT_PID と SSH_AUTH_SOCK を再設定すれば良い
ubuntu1410@ubuntu1410:~$ SSH_AGENT_PID=1709; export SSH_AGENT_PID;
ubuntu1410@ubuntu1410:~$ SSH_AUTH_SOCK=/tmp/ssh-uEZcqFuwDSKJ/agent.1708; export SSH_AUTH_SOCK;

# agentに登録済みの鍵を調べれば、どのプロセスを再利用するのか探るのに役立つかも
ubuntu1410@ubuntu1410:~$ ssh-add -l
2048 46:08:71:de:3d:ef:38:3b:5b:7a:96:7b:7a:82:b0:f0 id_rsa_ubuntu (RSA)
2048 0e:f4:77:b2:3d:0f:2d:e5:ca:a2:54:ca:3d:36:f9:f7 .ssh/id_rsa (RSA)

参考
http://d.hatena.ne.jp/flying-foozy/touch/20111206/1323160144

ssh設定メモ

ssh、scp、rsyncなどでパスワード、パスフレーズ入力不要とする設定。バッチで作業を自動化したいとか、単にパスワード入力が面倒といった場合に使える。

まずはsshの公開鍵、秘密鍵を作成する。公開鍵はファイル名に.pubが付いている方。
この時、パスフレーズは入力しない。

$ ssh-keygen -t rsa -C "コメントは日本語もOK"

続いて、公開鍵を所定の名前に変更する。

$ cp -p XXX.pub ~/.ssh/authorized_keys

設定は以上。別サーバから接続する際、例えば次のようにアクセスする。

$ ssh -i [秘密鍵] [ユーザ名]@[サーバ名] ls -l
$ scp -i [秘密鍵] [ユーザ名]@[サーバ名]:~/file1 ./
$ rsync --list-only -acvz --delete -e "ssh -i [秘密鍵]" [ユーザ名]@[サーバ名]:/tmp/ ~/  

Apache Batik を使って SVG 画像を PNG/GIF/JPEG に変換する

ベクタ形式の画像を手作りする方法としてはSVGが手っ取り早い。
まずは SVG 画像を用意し foo.svg として保存する。

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <circle cx="100" cy="100" r="100" fill="red" />
</svg>

次に Batik のラスタライザを使って PNG に変換する(上記画像のサイズ 200×200 を指定)。

C:\batik-1.7>java -jar batik-rasterizer.jar -w 200 -h 200 ..\foo.svg
About to transcode 1 SVG file(s)

Converting foo.svg to ..\foo.png ... ... success

C:\batik-1.7>

これで 200px × 200px の png 画像が出来上がる。
Web用の画像を作成する際は、デバイスピクセル比(device-pixel-ratio)を考慮し、実際に表示したいサイズ(px)の3倍の画像を作成して HTML や CSS で縮小するのが吉か。

仕事上の事情などで Inkscape 等が使えない場合、PNG から GIF/JPEG への変換は Windows のペイントで実現できる。透過 GIF を作成したい場合は Excel を使えば可能。
画像のリサイズはペイントで可能。

参考URL
Apache(tm) Batik SVG Toolkit - a Java-based toolkit for applications or applets that want to use images in the Scalable Vector Graphics (SVG)
mieki256's diary - SVG→PNG変換


その他:文字入りのサンプル

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
<linearGradient
   id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
  <stop offset="0%" stop-color="#fb0" />
  <stop offset="50%" stop-color="#fc4" />
  <stop offset="51%" stop-color="#fb0" />
  <stop offset="100%" stop-color="#fd9" />
</linearGradient>
<rect x="0" y="0" width="200" height="80"
      rx="10" ry="10" fill="url(#grad1)" />
<text x="100" y="50" font-family="Meiryo UI" text-anchor="middle"
      font-size="32" fill="white" stroke="black">あいうえお</text>
</svg>

UbuntuにEmacs24をインストールした時のログとinit.elの備忘録

インストー

ubuntu@ubuntu-14:~/c++/2.2$ sudo apt-get install emacs24-nox
[sudo] password for ubuntu: 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の特別パッケージがインストールされます:
  emacs24-bin-common emacs24-common emacs24-common-non-dfsg emacsen-common libasound2 libasound2-data
提案パッケージ:
  emacs24-el libasound2-plugins alsa-utils
以下のパッケージが新たにインストールされます:
  emacs24-bin-common emacs24-common emacs24-common-non-dfsg emacs24-nox emacsen-common libasound2 libasound2-data
アップグレード: 0 個、新規インストール: 7 個、削除: 0 個、保留: 63 個。
21.4 MB のアーカイブを取得する必要があります。
この操作後に追加で 87.0 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
取得:1 http://jp.archive.ubuntu.com/ubuntu/ trusty/main libasound2-data all 1.0.27.2-3ubuntu7 [26.3 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu/ trusty/main libasound2 amd64 1.0.27.2-3ubuntu7 [327 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu/ trusty/main emacsen-common all 2.0.7 [17.1 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu/ trusty/main emacs24-common-non-dfsg all 24.3+1-1 [4,421 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu/ trusty/main emacs24-common all 24.3+1-2ubuntu1 [13.7 MB]                                         
取得:6 http://jp.archive.ubuntu.com/ubuntu/ trusty/main emacs24-bin-common amd64 24.3+1-2ubuntu1 [104 kB]                                    
取得:7 http://jp.archive.ubuntu.com/ubuntu/ trusty/main emacs24-nox amd64 24.3+1-2ubuntu1 [2,807 kB]                                         
21.4 MB を 1分 43秒 で取得しました (207 kB/s)                                                                                                
以前に未選択のパッケージ libasound2-data を選択しています。
(データベースを読み込んでいます ... 現在 60398 個のファイルとディレクトリがインストールされています。)
Preparing to unpack .../libasound2-data_1.0.27.2-3ubuntu7_all.deb ...
Unpacking libasound2-data (1.0.27.2-3ubuntu7) ...
以前に未選択のパッケージ libasound2:amd64 を選択しています。
Preparing to unpack .../libasound2_1.0.27.2-3ubuntu7_amd64.deb ...
Unpacking libasound2:amd64 (1.0.27.2-3ubuntu7) ...
以前に未選択のパッケージ emacsen-common を選択しています。
Preparing to unpack .../emacsen-common_2.0.7_all.deb ...
Unpacking emacsen-common (2.0.7) ...
以前に未選択のパッケージ emacs24-common-non-dfsg を選択しています。
Preparing to unpack .../emacs24-common-non-dfsg_24.3+1-1_all.deb ...
Unpacking emacs24-common-non-dfsg (24.3+1-1) ...
以前に未選択のパッケージ emacs24-common を選択しています。
Preparing to unpack .../emacs24-common_24.3+1-2ubuntu1_all.deb ...
Unpacking emacs24-common (24.3+1-2ubuntu1) ...
以前に未選択のパッケージ emacs24-bin-common を選択しています。
Preparing to unpack .../emacs24-bin-common_24.3+1-2ubuntu1_amd64.deb ...
Unpacking emacs24-bin-common (24.3+1-2ubuntu1) ...
以前に未選択のパッケージ emacs24-nox を選択しています。
Preparing to unpack .../emacs24-nox_24.3+1-2ubuntu1_amd64.deb ...
Unpacking emacs24-nox (24.3+1-2ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for mime-support (3.54ubuntu1) ...
libasound2-data (1.0.27.2-3ubuntu7) を設定しています ...
libasound2:amd64 (1.0.27.2-3ubuntu7) を設定しています ...
emacsen-common (2.0.7) を設定しています ...
emacs24-common-non-dfsg (24.3+1-1) を設定しています ...
emacs24-common (24.3+1-2ubuntu1) を設定しています ...
emacs24-bin-common (24.3+1-2ubuntu1) を設定しています ...
update-alternatives: /usr/bin/ctags (ctags) を提供するために 自動モード で /usr/bin/ctags.emacs24 を使います
update-alternatives: /usr/bin/ebrowse (ebrowse) を提供するために 自動モード で /usr/bin/ebrowse.emacs24 を使います
update-alternatives: /usr/bin/emacsclient (emacsclient) を提供するために 自動モード で /usr/bin/emacsclient.emacs24 を使います
update-alternatives: /usr/bin/etags (etags) を提供するために 自動モード で /usr/bin/etags.emacs24 を使います
update-alternatives: /usr/bin/grep-changelog (grep-changelog) を提供するために 自動モード で /usr/bin/grep-changelog.emacs24 を使います
emacs24-nox (24.3+1-2ubuntu1) を設定しています ...
update-alternatives: /usr/bin/emacs (emacs) を提供するために 自動モード で /usr/bin/emacs24-nox を使います
Install emacsen-common for emacs24
emacsen-common: Handling install of emacsen flavor emacs24
Wrote /etc/emacs24/site-start.d/00debian-vars.elc
Wrote /usr/share/emacs24/site-lisp/debian-startup.elc
Processing triggers for libc-bin (2.19-0ubuntu6) ...
ubuntu@ubuntu-14:~/c++/2.2$ 

init.el

;; -*- Mode: Emacs-Lisp ; Coding: utf-8 -*-
(require 'cl)

;;;---------------------------------------------------------------------
;;; 標準機能の設定
;;;---------------------------------------------------------------------
;; スタートアップメッセージ非表示
(setq inhibit-startup-screen t)

;; tool-bar
;; (tool-bar-mode 0)

;; menu-bar
(menu-bar-mode 0)

;; TABの表示幅(初期値8から4に変更)
(setq default-tab-width 4)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72
                       76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144
                       148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216))

;; TABでなくスペースを使う
(setq-default indent-tabs-mode nil)

;; 改行コード表示
(setq eol-mnemonic-dos "(CRLF)")
(setq eol-mnemonic-mac "(CR)")
(setq eol-mnemonic-unix "(LF)")

;; メニューバーにファイルのフルパスを表示
;; (setq frame-title-format (format "%%f"))

;; ファイルの拡張子とモードの関連付け
(add-to-list 'auto-mode-alist '("\\.ddl$" . sql-mode))

;; 履歴を次回Emacs起動時にも保存する
(savehist-mode 1)

;; 対応する括弧を表示させる
(show-paren-mode 1)

;; 行が長くても自動的に折り返ししない
(auto-fill-mode 0)

;; シェルに合わせるためにC-hを後退に割り当てる
;; ※ヘルプは<f1>も使える
(global-set-key (kbd "C-h") 'delete-backward-char)

;; カレントバッファを閉じる。初期値は kill-sentence
(define-key global-map (kbd "M-k") 'kill-this-buffer)

;; 言語設定
(set-coding-system-priority 'utf-8 'euc-jp 'iso-2022-jp 'cp932)

;; 現在行に色をつける
(global-hl-line-mode 1)

;; リージョンに色をつける
(transient-mark-mode 1)

;; 行番号、桁番号を表示する
(line-number-mode 1)
(column-number-mode 1)

;; カーソル位置のファイルパスやアドレスを "C-x C-f" で開く
(ffap-bindings)

;; *.~ とかのバックアップファイルを一箇所にまとめる
;; (setq make-backup-files nil)
(setq make-backup-files t)
(setq backup-directory-alist
     (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
           backup-directory-alist
           )
     )
;; バックアップをバージョン管理する
(setq version-control t)
;; 新しいものをいくつ残すか
(setq kept-new-versions 10)
;; 古いものをいくつ残すか
(setq kept-old-versions 10)

;; .#* とかのバックアップファイルを作らない
(setq auto-save-default nil)

;; Emacsからの質問を y/n で回答
(fset 'yes-or-no-p 'y-or-n-p)

;; "C-m" に newline-and-indent を割り当てる(初期値は newline)
(define-key global-map (kbd "C-m") 'newline-and-indent)

;; GCを減らして軽くする
;; 現在のマシンパワーではもっと大きくしてもよい
;; デフォルトの1000倍とする
(setq gc-cons-threshold (* 1000 gc-cons-threshold))

;; ログの記録行数を増やす
(setq message-log-max 10000)

;; 履歴をたくさん保存する
(setq history-length 10000)

;; キーストロークをエコーエリアに早く表示する
(setq echo-keystrokes 0.1)

;; 大きいファイルを開こうとしたときに警告を発生させる
;; デフォルトは10MBなので50MBに拡張する
(setq large-file-warning-threshold (* 50 1024 1024))

;; emacs24で右から左に書く言語のための設定のようだが,デフォルトでは無効にしたほう が動作が軽快らしい
;; http://www.kaichan.mydns.jp/~kai/orgweb/init.html
(setq-default bidi-display-reordering nil
              bidi-paragraph-direction (quote left-to-right))


;;;---------------------------------------------------------------------
;;; 標準pluginの設定
;;;---------------------------------------------------------------------
;; 行番号表示
(require 'linum)
(global-linum-mode 1)

;; cua-mode: 矩形編集を強力にする
;; リージョン選択中に C-RET で矩形編集に入る、C-g で終了
(require 'cua-mode nil t)
(cua-mode t)
(setq cua-enable-cua-keys nil)

;; org-modeでHTML出力した時のHTML末尾に出力される"Validate XHTML 1.0"を抑制する
(setq org-export-html-validation-link nil)

;; インライン画像の表示
(setq org-startup-with-inline-images t)

;; 特殊文字の色付け
;; http://masutaka.net/chalow/2011-10-12-1.html
(global-whitespace-mode 1)
(setq whitespace-style '(face tabs tab-mark spaces space-mark newline newline-mark))
(setq whitespace-space-regexp "\\(\u3000+\\)")
(setq whitespace-display-mappings
         '((space-mark   ?\u3000 [?\u25a1])                ; 全角スペースを□で表わす
           (tab-mark     ?\t     [?\u00BB ?\t] [?\\ ?\t])  ; tab - left quote mark
           (newline-mark ?\n     [?\u21B5 ?\n] [?$ ?\n])   ; eol - overscore
           ))
(set-face-foreground 'whitespace-tab "#7594FF")
(set-face-background 'whitespace-tab 'nil)
(set-face-foreground 'whitespace-space "#7594FF")
(set-face-background 'whitespace-space 'nil)
(set-face-foreground 'whitespace-newline "#7594FF")
(set-face-background 'whitespace-newline 'nil)


;;;---------------------------------------------------------------------
;;; 追加pluginの設定
;;;---------------------------------------------------------------------
(add-to-list 'load-path "~/.emacs.d/elisp/")

;; auto-install
(require 'auto-install)
(setq auto-install-directory "~/.emacs.d/elisp")
(auto-install-update-emacswiki-package-name t)
(auto-install-compatibility-setup)

;; anything
(require 'anything-startup)
(global-set-key (kbd "C-:") 'anything-for-files)
;; 変数のチューニング
;; 打鍵から更新されるまでの遅延時間
(setq anything-input-idle-delay 0.1)
;; 候補を表示するまでの時間
(setq anything-idle-delay 0.1)
;; 表示されている情報源以外をdelayed扱いにする
(setq anything-quick-update nil)

;; recentfの拡張
;; ディレクトリもrecentfの対象にする
;; (install-elisp-from-emacswiki "recentf-ext.el")
;; 最近のファイル500個を保存する
(setq recentf-max-saved-items 500)
(require 'recentf-ext)

;; lixpxmp
;; (install-elisp "http://www.emacswiki.org/emacs/download/lispxmp.el")
(require 'lispxmp)

;; LaTeXの文書クラスについては以下を参照
;; http://keizai.xrea.jp/latex/tutorial/class.html
;; init.elの設定については以下を参照
;; http://d.hatena.ne.jp/tamura70/20100217/org
;; http://skalldan.wordpress.com/2011/06/10/%E5%9F%B7%E7%AD%86%E7%92%B0%E5%A2%83/
(setq org-export-latex-coding-system 'shift_jis)
(setq org-export-latex-date-format "%Y-%m-%d")
(setq org-export-latex-classes nil)
(add-to-list 'org-export-latex-classes
  '("jsarticle"
    "\\documentclass[a4j]{jsarticle}"
    ("\\section{%s}" . "\\section*{%s}")
    ("\\subsection{%s}" . "\\subsection*{%s}")
    ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
    ("\\paragraph{%s}" . "\\paragraph*{%s}")
    ("\\subparagraph{%s}" . "\\subparagraph*{%s}")
))
(setq org-export-latex-packages-alist
  '(("AUTO" "inputenc"  t)
    ("T1"   "fontenc"   t)
;;     ("deluxe,expert,multi"     "otf"   nil)
;;     ;; (""     "txfonts"   nil)
;; ;;     ;; ...                                     ; 使用するパッケージを適宜追加
    ))


;;; --------------------------------------------------------------------
;;;  カスタム設定
;;; --------------------------------------------------------------------
;; http://d.hatena.ne.jp/rubikitch/20100210/emacs
;; C-x o は激しく押しにくい
;; other-windowは分割していないときには何も動作しない。せっかく1ストロークにわりあてたのに、
;; これでは勿体ない
;; 分割してない状態のときにも働いてもらおう。分割してないときは、分割するようにする
;; 押しやすいキーには、状況に応じて空気を読んでくれるコマンドを割り当てるのが
;; 使い勝手を向上させるポイント
;; 初期値は transpose-chars だが使わないので
(defun other-window-or-split ()
 (interactive)
 (when (one-window-p)
   (split-window-horizontally))
 (other-window 1))
(global-set-key (kbd "C-t") 'other-window-or-split)

;; tmpファイルを作成する
(defun tmpfile ()
 (interactive)
 (let* ((file (expand-file-name
               (format-time-string
                ;;"%Y/%m/%Y-%m-%d-%H%M%S." (current-time))
                "%Y%m%d.%H%M%S.txt" (current-time))
               "~/"))
        (dir (file-name-directory file)))
   (make-directory dir t)
   (find-file-other-window (read-string "tmpfile: " file))))

;; 折り返し表示ON/OFF
(defun toggle-truncate-lines ()
 "折り返し表示をトグル動作します."
 (interactive)
 (if truncate-lines
     (setq truncate-lines nil)
   (setq truncate-lines t))
 (recenter))
(global-set-key "\C-c\C-l" 'toggle-truncate-lines)  ; 折り返し表示ON/OFF

VMWare 上の Ubuntu を固定IPにする方法

ubuntu-14.04-server-amd64VMWare Player 上にインストールした時のメモ。

インストール自体は何事も無く終了。OpenSSH Server だけインストールし、Windows からは rlogin/telnet/ssh(クライアント)ターミナルソフト (←ファイル転送も簡単にできるのでこれは便利!)で接続する。

IPアドレスが変わってしまうと面倒なので、固定IPにしたい。
Ubuntu側で固定IPにする方法も考えられるが、VMWareUbuntu に対して割り振るIPを固定にしておけば、Ubuntu 側の設定は何も変更する必要ない。

詳細は VMWare Player上で動作するUbuntuのIPアドレスを固定化する | 近藤嘉雪のプログラミング工房日誌 に書かれている。
要は C:\ProgramData\VMware\vmnetdhcp.conf の一番下に下記を追加すればよい。

host VMnet8 {
    hardware ethernet 00:0c:29:92:2a:3a;
    fixed-address 192.168.233.101;
}

hardware ethernet には Ubuntu の ifconfig で表示される MACアドレス
fixed-address には割り当てたいIPを指定する。

複数台仮想マシンを起動する場合は次のように記述すれば、2台とも固定IPが振られた。VMnet8-で始まる名前にすれば良いようだ。

host VMnet8 {
    hardware ethernet 00:0c:29:92:2a:3a;
    fixed-address 192.168.233.101;
}
host VMnet8-1410 {
    hardware ethernet 00:0c:29:9f:e7:cc;
    fixed-address 192.168.233.102;
}