2007年11月アーカイブ

crontab

| | コメント(0) | トラックバック(0)

 

[root@localhost ~]# ps -Af | grep cron
root      2278     1  0 21:18 ?        00:00:00 crond
root      3305  3240  0 22:44 pts/0    00:00:00 grep cron
[root@localhost ~]# /var/spool/cron/root ← ユーザー毎にcrontabの設定をする。

 

書式

<分> <時> <日> <月> <曜日> <コマンド>

<分> 0~59までの整数

<時> 0~23までの整数

<日> 1~31までの整数

<月> 1~12までの整数

<曜日> 0~7までの整数 (0,7 : 日曜~6:土曜日)

<コマンド> 実行するコマンド,シェルスクリプトなど。

 

(日次例)
23時45分に毎日実行

45 23 * * * /home/admin/filechk.sh

(週次例)
月曜日の9時と12時に実行 (複数の値を指定しているので,","で9時と12時を区切っています。

0 9,12  * * 1  /home/admin/filechk.sh

(2時間毎)
2時間毎にジョブを実行 (2分,2時間などと設定する場合は,"*/2"のように設定します。

0 */2  * * *  /home/admin/filechk.sh

システム用のcrontabファイル(/etc/crontab)もあります。このファイルでは実行ユーザー名の指定をします。

 

crontab.jpg

/etc/cron.deny  /etc/crontab
/etc/cron.d:
/etc/cron.daily:
/etc/cron.hourly:
/etc/cron.monthly:
/etc/cron.weekly:

※システムダウン中に実行されるべきジョブがシステム復旧後に自動的に実行されるようにするには,

anacronを利用します。

[root@localhost ~]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

1       65      cron.daily              run-parts /etc/cron.daily
7       70      cron.weekly             run-parts /etc/cron.weekly
30      75      cron.monthly            run-parts /etc/cron.monthly
[root@localhost ~]#

 

おまけ:

ジョブを一回実行する場合は,ATコマンドを利用します。

対話モード

[root@localhost ~]# at 23:40
at> /sbin/shutdown -h now
at> <EOT>                      ←Ctrl+Dで終了
job 1 at 2007-11-25 23:40
[root@localhost ~]# at -l
1       2007-11-25 23:40 a root
[root@localhost ~]#

『結果 ↓ 無事に実行されました。』 

[root@localhost ~]# date
2007年 11月 25日 日曜日 23:40:00 JST
[root@localhost ~]#
Broadcast message from root (Sun Nov 25 23:40:00 2007):

The system is going down for system halt NOW!

 

 

非対話モード

[root@localhost ~]# at -f /home/admin/at.sh 23:30
job 2 at 2007-11-25 23:30
[root@localhost ~]# at -l
1       2007-11-25 23:40 a root
2       2007-11-25 23:30 a root
[root@localhost ~]#

 

真夜中:midnight 今日:today 明日:tomorrow 2日後:now + 2days 2週間後の10時PM: 22:00 + 2weeks

※ at -dコマンドで実行中のジョブを削除出来ます。

※ atqコマンド, atrmコマンド


cronやatのアクセス制御

 /etc/cron.allow ← 登録されたユーザーのみCronを利用出来る。

 /etc/cron.deny ← cron.allowが無ければ,cron.denyに記述されていない全てのユーザーが利用出来る。

※どちらのファイルも無ければ,全てのユーザーがcronを利用出来る。

/etc/at.allow

/etc/at.deny

※どちらのファイルも無ければ,rootだけがatを利用出来る。

ログローテーション

[root@localhost ~]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
# 毎週ログのローテーションを行う
weekly

# keep 4 weeks worth of backlogs
# バックログを4週間のこす
rotate 4

# create new (empty) log files after rotating old ones
# 古いファイルをローテーションさせたら,空のログファイルを作成する。
create

# uncomment this if you want your log files compressed
# ログファイルを圧縮する
compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
# ローテーション周期を1ヶ月とする。権限とログの数
/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
[root@localhost ~]#

[root@localhost ~]# ls -l /var/log/secure*
-rw------- 1 root root 5078 11月 24 22:40 /var/log/secure
-rw------- 1 root root 1335 11月 17 23:31 /var/log/secure.1
-rw------- 1 root root 2195 11月 16 00:19 /var/log/secure.2
-rw------- 1 root root 4357 11月  4 23:18 /var/log/secure.3
-rw------- 1 root root  918 11月  3 00:49 /var/log/secure.4
[root@localhost ~]#


[root@localhost ~]# ls -l /var/log/wtmp
wtmp    wtmp.1

 

※  logrotateの設定は、/etc/logrotate.confと/etc/logrotate.dディレクトリにある各設定ファイルで行います。

※  各ログファイルの設定は、/etc/logrotated.dディレクトリの設定ファイルで行います。syslogdで設定されたログの設定ファイルは、/etc/logrotated.d/syslog

 

[root@localhost ~]# cat  /etc/logrotate.d/syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}
[root@localhost ~]#

 

此方のサイトが,参考になります。

 

lastlog

| | コメント(0) | トラックバック(0)

[root@localhost ~]# who
admin    pts/0        2007-11-24 22:25 (192.168.11.2)
[root@localhost ~]# w
 00:03:46 up  2:14,  1 user,  load average: 0.04, 0.01, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
admin    pts/0    192.168.11.2     22:25    0.00s  0.67s  0.49s sshd: admin [priv]
[root@localhost ~]# last
admin    pts/0        192.168.11.2     Sat Nov 24 22:25   still logged in
reboot   system boot  2.6.18-8.1.14.el Sat Nov 24 21:49          (02:14)
reboot   system boot  2.6.18-8.1.14.el Fri Nov 23 22:28          (14:50)
admin    pts/1        192.168.11.2     Mon Nov 19 00:27 - down   (00:32)
admin    pts/1        192.168.11.2     Mon Nov 19 00:27 - 00:27  (00:00)
admin    pts/0        192.168.11.2     Sun Nov 18 14:11 - down   (10:48)
reboot   system boot  2.6.18-8.1.14.el Sun Nov 18 14:09          (10:49)
admin    pts/1        192.168.11.2     Sun Nov 18 00:36 - down   (00:43)
admin    pts/0        192.168.11.2     Sat Nov 17 23:31 - 00:45  (01:13)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 17 23:13          (02:07)
admin    pts/0        192.168.11.2     Sat Nov 17 02:31 - down   (00:28)
admin    pts/0        192.168.11.2     Fri Nov 16 00:00 - 00:19  (00:19)
reboot   system boot  2.6.18-8.1.14.el Thu Nov 15 23:51         (1+03:09)
admin    pts/0        192.168.11.2     Sat Nov 10 22:48 - down   (02:43)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 10 22:19          (03:13)
admin    pts/0        192.168.11.2     Sat Nov 10 01:53 - down   (01:28)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 10 00:53          (02:28)
admin    pts/0        192.168.11.2     Sun Nov  4 22:49 - down   (01:35)
reboot   system boot  2.6.18-8.1.14.el Sun Nov  4 22:26          (01:58)
admin    pts/1        192.168.11.2     Sun Nov  4 02:14 - 02:14  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:14 - 02:14  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:04 - 02:04  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:00 - 02:01  (00:00)
admin    pts/0        192.168.11.2     Sat Nov  3 22:57 - down   (03:35)
reboot   system boot  2.6.18-8.1.14.el Sat Nov  3 21:37          (04:55)
admin    pts/0        192.168.11.2     Sat Nov  3 02:13 - down   (00:00)

wtmp begins Sat Nov  3 02:13:55 2007
[root@localhost ~]# lastlog
ユーザ名         ポート   場所             最近のログイン
root                                       **一度もログインはありません**
bin                                        **一度もログインはありません**
daemon                                     **一度もログインはありません**
adm                                        **一度もログインはありません**
lp                                         **一度もログインはありません**
sync                                       **一度もログインはありません**
shutdown                                   **一度もログインはありません**
halt                                       **一度もログインはありません**
mail                                       **一度もログインはありません**
news                                       **一度もログインはありません**
uucp                                       **一度もログインはありません**
operator                                   **一度もログインはありません**
games                                      **一度もログインはありません**
gopher                                     **一度もログインはありません**
ftp                                        **一度もログインはありません**
nobody                                     **一度もログインはありません**
rpm                                        **一度もログインはありません**
dbus                                       **一度もログインはありません**
avahi                                      **一度もログインはありません**
mailnull                                   **一度もログインはありません**
smmsp                                      **一度もログインはありません**
ntp                                        **一度もログインはありません**
apache                                     **一度もログインはありません**
nscd                                       **一度もログインはありません**
vcsa                                       **一度もログインはありません**
haldaemon                                  **一度もログインはありません**
rpc                                        **一度もログインはありません**
rpcuser                                    **一度もログインはありません**
sshd                                       **一度もログインはありません**
pcap                                       **一度もログインはありません**
xfs                                        **一度もログインはありません**
gdm                                        **一度もログインはありません**
admin            pts/0    192.168.11.2     土 11月 24 22:25:36 +0900 2007
mysql                                      **一度もログインはありません**
administrator                              **一度もログインはありません**
[root@localhost ~]#

 

━━━ 追記 ━━━

lastコマンド :  /var/log/wtmp
whoコマンド  :   /var/run/utmp 

書式:ファシリティ(出力元「カーネル,プロセスなど」).プライオリティ 出力先

auth, authpriv 認証システム
cron           CRONの出力
daemon         デーモンの出力
kern           カーネルによる出力
lpr            印刷関連
mail           メールシステム
syslog         syslog機能
local0~local7 独自設定

以下のディフォルトsyslog.confは優先順位を全て"*"に設定してあります。
*は以下のプライオリティを含みます。
【emerg, alert, crit, err, warning, notice,info,debug,none】

[root@localhost ~]# cat /etc/syslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
# kern.*                                                 /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog

# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 *

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
[root@localhost ~]#

ログの出力先:

ファイル名  ファイルに出力する
@ホスト名  リモートホストのsyslogに出力する。
ユーザー名  ユーザーの端末に出力する
/dev/console コンソールに出力する
*             全てのユーザーに通知する。

ホームディレクトリー作成時に,配布したいディフォルトファイルは/etc/skel/
においておきます。

[root@localhost ~]# ls -al /etc/skel/
合計 56
drwxr-xr-x  2 root root  4096 10月  5 03:55 .
drwxr-xr-x 92 root root 12288 11月 24 21:50 ..
-rw-r--r--  1 root root    24  1月  6  2007 .bash_logout
-rw-r--r--  1 root root   176  1月  6  2007 .bash_profile
-rw-r--r--  1 root root   124  1月  6  2007 .bashrc
-rw-r--r--  1 root root   515  1月  6  2007 .emacs
[root@localhost ~]#

 

※もし常に初期設定時,必要なファイルがあればここに設定しておくとユーザー作成の時に自動的に

  必要なファイルがコピーされます。 

 /etc/passwd
ユーザー名:パスワード:UID:GID:コメント:ホームディレクトリー:ディフォルトシェル
※パスワードはシャドーパスワード(/etc/shadow)を利用しているのでxになっています。

[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
admin:x:500:500:admin:/home/admin:/bin/bash
mysql:x:501:501::/home/mysql:/bin/bash
[root@localhost ~]#


[root@localhost ~]# cat /etc/shadow
root:$1$vTSDEX$zQi8NSx8dghmYbDsV8TS1AGQ.:13790:0:99999:7:::
bin:*:13790:0:99999:7:::
daemon:*:13790:0:99999:7:::
xfs:!!:13790:0:99999:7:::
gdm:!!:13790:0:99999:7:::
admin:$1$vSMsQdseS$.hYb8ArSdMSDB1YZufrPu1:13790:0:99999:7:::
mysql:!!:13793:0:99999:7:::

 

/etc/group
グループ名:グループパワード:GID:グループメンバー
※グループメンバー用のパスワードはシャドーパスワード(/etc/gshadow)を利用しているのでxになってます。
※グループメンバーが1人で無い場合は「,」で区切ります。

[root@localhost ~]# cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
xfs:x:43:
gdm:x:42:
admin:x:500:
mysql:x:501:
[root@localhost ~]#


[root@localhost ~]# cat /etc/gshadow
root:::root
bin:::root,bin,daemon
daemon:::root,bin,daemon
xfs:x::
gdm:x::
admin:!!::
mysql:!::
[root@localhost ~]#


■ユーザー追加
[root@localhost ~]# /usr/sbin/useradd

※ -c <コメント>
※ -d ホームディレクトリー指定
※ -g グループ名/GID指定 プライマリーグループ
※ -G グループ名/GID指定 プライマリーグループ以外の所属するグループ
※ -s <パス> ログインシェルを指定
※ -D ディフォルトの設定値を表示若しくは設定

[root@localhost ~]# /usr/sbin/useradd -c "Wheel Group User" -d /home/administrator -g wheel -s /bin/bash administrator

[root@localhost ~]# cat /etc/passwd | grep administrator
administrator:x:502:10:Wheel Group User:/home/administrator:/bin/bash
[root@localhost ~]#

■ユーザーアカウント変更
[root@localhost ~]# /usr/sbin/usermod

※ -c <コメント> コメント追加
※ -d <パス>    ホームディレクトリー変更
※ -g グループ名/GID指定 プライマリーグループ変更
※ -G グループ名/GID指定 所属するグループ変更
※ -s <パス> ログインシェルを変更
※ -L パスワードをロックして一時的に無効化する。
※ -U パスワードのロックを解除する

[root@localhost ~]# /usr/sbin/usermod -G wheel admin
[root@localhost ~]# cat /etc/passwd | grep admin
admin:x:500:500:管理者:/home/admin:/bin/bash <---プライマリーグループは変わらない
administrator:x:502:10:Wheel Group User:/home/administrator:/bin/bash
[root@localhost ~]# id admin
uid=500(admin) gid=500(admin) 所属グループ=500(admin),10(wheel) context=user_u:system_r:unconfined_t
[root@localhost ~]#

usermoddで長期休暇,辞めたユーザーのアカウントを利用不可能にしておく。
[root@localhost ~]# /usr/sbin/usermod -L administrator 
[root@localhost ~]#


■ユーザーアカウント削除
[root@localhost ~]# /usr/sbin/userdel

※ -r ホームディレクトリーも一緒に削除する。
-r無しで削除した場合は後程自分でrmコマンドでホームディレクトリーを削除する。
 

■パスワードコマンド
[root@localhost ~]# /usr/bin/passwd
passwd 「オプション」「ユーザー名」
※ -l パスワードをロックして一時的に無効にする。
※ -u パスワードのロックを解除する。

■グループ情報変更
[root@localhost ~]# /usr/sbin/groupmod
groupmod グループ名

※ -g <GID> GIDを変更する
※ -n <グループ名> グループ名を変更する

■グループ削除
[root@localhost ~]# /usr/sbin/groupdel
groupdel グループ名

■グループパスワード変更
[root@localhost ~]# /usr/bin/gpasswd
※殆ど利用されてません。


■シャドーパスワード
/etc/shadow (スーパーユーザーのみアクセス可能なファイルなので安全)
インストール時にシャドーパスワードを設定しなかった場合は,
pwconvコマンドを利用して切り替える事が出来ます。
シャドーパスワードから旧来のパスワードに戻すには,pwunconvコマンドを
利用して対応します。但しセキュリティ上良くないのでやらない方が
良いと思います。

[root@localhost ~]# /usr/sbin/pwconv
[root@localhost ~]# /usr/sbin/pwunconv

PHPでフレームワークのsymfonyを利用する事になったので,とりあえず家で予習です。

とりあえず,インストールしてみました。

[root@localhost bin]# ls
pear  peardev  pecl  php  php-config  phpize

[root@localhost bin]# ./pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded

[root@localhost bin]# ./pear install symfony/symfony
downloading symfony-1.0.8.tgz ...
Starting to download symfony-1.0.8.tgz (1,908,095 bytes)
..........................done: 1,908,095 bytes
install ok: channel://pear.symfony-project.com/symfony-1.0.8
[root@localhost bin]#

[root@localhost bin]# ls
pear  peardev  pecl  php  php-config  phpize  symfony
[root@localhost bin]#

[root@localhost bin]# ./symfony -V
symfony version 1.0.8
[root@localhost bin]#

symfony.jpg

 

[admin@localhost extra]$ grep -v ^# httpd-info.conf


<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .example.com
</Location>


<Location /server-info>
    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from .example.com
</Location>
[admin@localhost extra]$ egrep -v -e "#" httpd-info.conf


<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .example.com
</Location>


<Location /server-info>
    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from .example.com
</Location>
[admin@localhost extra]$

 

[admin@localhost extra]$ egrep -e "SetHandler" httpd-info.conf
    SetHandler server-status
    SetHandler server-info
[admin@localhost extra]$

 

正規表現利用.jpg

バッチを組むときに使える,testコマンド

[root@localhost ~]# test -f t; echo $? <----ファイルが無い
1
[root@localhost ~]# test -f lslink ; echo $? <----ファイルが有る
0
[root@localhost ~]#

==========================================================

testコマンド

説明
       test は条件式 expr を評価した結果によって、 0 (真) または 1 (偽) を終了ステータスとして返す。

       式 の各部分はそれぞれ分離された引数でなければならない。式は単項式あるいは二項式である。 test はファイ
       ルのステータス調査、文字列操作、数値の比較演算を行うことができる。

       ほとんどのシェルには同名の組み込みコマンドがあるので、単に 'test' として実行すると、ここで記述され た
       ものとは異なった機能のものが実行されるだろう。

   ファイル形式のテスト
       -b file
              file が存在し、ブロックスペシャルファイルであれば真。
       -c file
              file が存在し、キャラクタスペシャルファイルであれば真。
       -d file
              file が存在し、ディレクトリであれば真。
       -f file
              file が存在し、通常ファイル (regular file) であれば真。
       -h file
       -L file
              file が存在し、シンボリックリンクであれば真。
       -p file
              file が存在し、名前付きパイプ (named pipe) であれば真。
       -S file
              file が存在し、ソケットであれば真。
       -t [fd]
              fd が端末でオープンされていれば真。 fd が省略された場合のデフォルト値は 1 (標準出力)。

   ファイルのパーミッションのテスト
       -g file
              file が存在し、set GID されていれば真。
       -k file
              file が存在し、 sticky ビットが立っていれば真。
       -r file
              file が存在し、読み取り可能であれば真。
       -u file
              file が存在し、 set SUID されていれば真。
       -w file
              file が存在し、書き込み可能であれば真。
       -x file
              file が存在し、実行可能であれば真。
       -O file
              file が存在し、現在の実効ユーザー id による所有であれば真。
       -G file
              file が存在し、現在の実効グループ id による所有であれば真。

   ファイル特性のテスト
       -e file
              file が存在すれば真。
       -s file
              file が存在し、サイズが 0 より大きければ真。
       file1 -nt file2
              file1 が file2 より (修正時刻で比較して) 新しければ真。
       file1 -ot file2
              file1 が file2 より古ければ真。
       file1 -ef file2
              file1 と file2 のデバイス番号と i-ノード番号が共に等しければ真。

   文字列のテスト
       string
       -n string
              string の長さが 0 より大きければ真。
       -z string
              string の長さが 0 であれば真。
       string1 = string2
              二つの文字列が等しければ真。
       string1 != string2
              二つの文字列が等しくなければ真。

   数値のテスト
       arg1 OP arg2
              OP は -eq, -ne, -lt, -le, -gt, -ge のいずれか。これらの代数二項演算子は、それぞれ arg1 が arg2
              (に等しい、に等しくない、より小さい、より小さいか等しい、より大きい、より大きいか等しい) 条 件
              を 満たせば真。 arg1 および arg2 は正の整数、負の整数をとることができる。また -l string という
              特殊な式を指定することもでき、この場合は string の長さとなる。

   テストの論理結合
       ! expr expr が偽であれば真。
       expr1 -a expr2
              expr1 と expr2 の両方が真であれば真。
       expr1 -o expr2
              expr1 か expr2 のどちらかが真であれば真。

==========================================================

 

############################################

(例) 以下のような内容でバッチを作成してみる。

############################################

[root@localhost ~]# cat filechk.sh
#!/bin/bash

if test -f lsld
then
        echo "ファイルがありました。シェルを実行します"
        ./lsld
else
        "スクリプトが存在しませんでした,処理を中止いたします"
fi
[root@localhost ~]#

 

 

↓ 実行

 

[root@localhost ~]# ./filechk.sh
ファイルがありました。シェルを実行します
Link Files
Directories
drwxr-xr-x 2 admin admin     4096 10月  4 21:11 Desktop
drwxr-xr-x 4 root  root      4096 10月  8 00:16 postsource
drwxr-xr-x 3 root  root      4096 10月 27 01:50 source
[root@localhost ~]#

 

追記: test = [ ] コマンドです。

[root@localhost ~]# cat filechk2.sh
#!/bin/bash

if [ -f lsld ]

then
        echo "ファイルがありました。シェルを実行します"
        ./lsld
else
        "スクリプトが存在しませんでした,処理を中止いたします"
fi


[root@localhost ~]# ./filechk2.sh
ファイルがありました。シェルを実行します
Link Files
Directories
drwxr-xr-x 2 admin admin     4096 10月  4 21:11 Desktop
drwxr-xr-x 3 admin admin     4096  8月 12  2002 atmarkit5th
drwxr-xr-x 4 root  root      4096 10月  8 00:16 postsource
drwxr-xr-x 3 root  root      4096 10月 27 01:50 source
drwxr-xr-x 5  1000  1000     4096  5月 12  2007 vim71
[root@localhost ~]#

[root@localhost ~]# cat lsld <-----サンプルシェルスクリプト
ls -l $1 > lslink
echo "Link Files"
grep '^l' lslink
echo "Directories"
grep '^d' lslink
[root@localhost ~]#


[root@localhost etc]# source lsld  <-----(「sourceコマンド」, 「. lsld」, 「./lsldなど(chmod755後)」)
Link Files
lrwxrwxrwx  1 root root      22 10月  5 04:31 grub.conf -> ../boot/grub/grub.conf
lrwxrwxrwx  1 root root      11 10月  5 03:27 init.d -> rc.d/init.d
lrwxrwxrwx  1 root root       7 10月  5 03:47 rc -> rc.d/rc
lrwxrwxrwx  1 root root      13 10月  5 03:47 rc.local -> rc.d/rc.local
lrwxrwxrwx  1 root root      15 10月  5 03:47 rc.sysinit -> rc.d/rc.sysinit
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc0.d -> rc.d/rc0.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc1.d -> rc.d/rc1.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc2.d -> rc.d/rc2.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc3.d -> rc.d/rc3.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc4.d -> rc.d/rc4.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc5.d -> rc.d/rc5.d
lrwxrwxrwx  1 root root      10 10月  5 03:47 rc6.d -> rc.d/rc6.d
lrwxrwxrwx  1 root root      11 10月  5 03:29 rmt -> ../sbin/rmt
Directories
drwxr-xr-x  2 root root    4096  3月 15  2007 NetworkManager
drwxr-xr-x  8 root root    4096 10月  5 04:31 X11
drwxr-xr-x  4 root root    4096 10月  5 03:59 acpi
drwxr-xr-x  4 root root    4096 10月  5 03:38 alsa
drwxr-xr-x  2 root root    4096 10月  5 04:22 alternatives
drwxr-x---  2 root root    4096 10月  5 03:51 audit
drwxr-xr-x  4 root root    4096 10月  5 03:47 avahi
drwxr-xr-x  2 root root    4096 11月 10 22:19 blkid
drwxr-xr-x  2 root root    4096 10月  5 03:59 bluetooth
drwxr-xr-x  2 root root    4096 10月  5 03:29 bonobo-activation
drwx------  2 root root    4096  3月 15  2007 cron.d
drwxr-xr-x  2 root root    4096 10月  5 04:04 cron.daily
drwxr-xr-x  2 root root    4096  1月  6  2007 cron.hourly
drwxr-xr-x  2 root root    4096 10月  5 03:34 cron.monthly
drwxr-xr-x  2 root root    4096 10月  5 03:45 cron.weekly
drwxr-xr-x  5 root lp      4096 10月  5 03:48 cups
drwxr-xr-x  3 root root    4096 10月  5 03:39 dbus-1
drwxr-xr-x  2 root root    4096 10月  5 03:37 default
drwxr-xr-x  2 root root    4096 10月  5 03:38 depmod.d
drwxr-xr-x  2 root root    4096  1月  6  2007 desktop-profiles
drwxr-xr-x  3 root root    4096 10月  5 03:52 dev.d
drwxr-xr-x  2 root root    4096 10月  5 03:59 firmware
drwxr-xr-x  4 root root    4096 10月  5 03:37 fonts
drwxr-xr-x  2 root root    4096 10月  5 03:49 foomatic
drwxr-xr-x  2 root root    4096 10月  5 04:26 gaim
drwxr-xr-x  6 root root    4096 10月  5 03:39 gconf
drwxr-xr-x  7 root root    4096 10月  5 04:12 gdm
drwxr-xr-x  2 root root    4096 10月  5 04:18 ghostscript
drwxr-xr-x  4 root root    4096  1月  7  2007 gimp
drwxr-xr-x  3 root root    4096 10月  5 04:04 gnome-vfs-2.0
drwxr-xr-x  2 root root    4096 10月  5 04:08 gre.d
drwxr-xr-x  3 root root    4096 10月  5 03:40 gtk-2.0
drwxr-xr-x  3 root root    4096 10月  5 03:52 hal
drwxr-xr-x  2 root root    4096 10月  5 03:30 iproute2
drwxr-xr-x  2 root root    4096 10月 14 03:01 ld.so.conf.d
drwxr-xr-x  2 root root    4096 10月 14 17:57 logrotate.d
drwxr-xr-x  4 root root    4096 10月  5 04:02 logwatch
drwxr-xr-x  2 root root    4096 10月  5 03:57 lsb-release.d
drwxr-xr-x  4 root root    4096 10月 14 22:52 lvm
drwxr-xr-x  2 root root    4096 10月  5 03:49 mail
drwxr-xr-x  2 root root    4096 10月  5 03:52 makedev.d
drwxr-xr-x  2 root root    4096 10月  5 03:34 mgetty+sendfax
drwxr-xr-x  2 root root    4096 10月  5 03:38 modprobe.d
drwxr-xr-x  2 root root    4096 10月  5 03:42 netplug
drwxr-xr-x  2 root root    4096 10月  5 03:42 netplug.d
drwxr-xr-x  2 root root    4096 10月  5 04:23 ntp
drwxr-xr-x  2 root root    4096  1月  6  2007 oddjob
drwxr-xr-x  2 root root    4096 10月  5 04:11 oddjobd.conf.d
drwxr-xr-x  3 root root    4096 10月  5 03:37 openldap
drwxr-xr-x  2 root root    4096  3月 30  2007 opt
drwxr-xr-x  2 root root    4096 11月 10 02:38 pam.d
drwxr-xr-x  2 root root    4096 10月  5 03:59 pam_pkcs11
drwxr-xr-x  3 root root    4096 10月  5 03:38 pango
drwxr-xr-x  2 root root    4096 10月  5 03:57 pcmcia
drwxr-xr-x  6 root root    4096 10月  5 03:37 pki
drwxr-xr-x  5 root root    4096 10月  5 03:48 pm
drwxr-xr-x  3 root root    4096 10月  5 03:58 ppp
drwxr-xr-x  2 root root    4096 10月  5 04:04 profile.d
drwxr-xr-x  3 root root    4096 10月  5 03:59 racoon
drwxr-xr-x 10 root root    4096 10月  5 03:47 rc.d
drwxr-xr-x  2 root root    4096 10月  5 04:02 readahead.d
drwxr-xr-x  2 root root    4096 10月  5 04:05 reader.conf.d
drwxr-xr-x  2 root root    4096 10月  5 03:57 redhat-lsb
drwxr-xr-x  3 root root    4096 10月  5 03:58 rhgb
drwxr-xr-x  2 root root    4096 10月  5 03:57 rpm
drwxr-xr-x  2 root root    4096  3月 22  2007 rwtab.d
drwxr-xr-x  2 root root    4096 10月  5 03:48 samba
drwxr-xr-x  2 root root    4096 10月  5 04:22 sane.d
drwxr-xr-x  2 root root    4096  1月  7  2007 sasl2
drwxr-xr-x  2 root root    4096 10月  5 03:40 scim
drwxr-xr-x  4 root root    4096 10月  5 03:47 security
drwxr-xr-x  3 root root    4096 10月 14 16:53 selinux
drwxr-xr-x  2 root root    4096 10月  5 03:58 setuptool.d
drwxr-xr-x  2 root root    4096 10月  5 03:59 sgml
drwxr-xr-x  2 root root    4096 10月  5 03:55 skel
drwxr-xr-x  2 root root    4096  3月 15  2007 smrsh
drwxr-xr-x  3 root root    4096  3月 15  2007 sound
drwxr-xr-x  2 root root    4096 10月  4 21:26 ssh
drwxr-xr-x  2 root root    4096  1月  7  2007 stunnel
drwxr-xr-x  2 root root    4096  3月 15  2007 subversion
drwxr-xr-x 10 root root    4096 10月 14 22:52 sysconfig
drwxr-xr-x  4 root root    4096 10月  5 03:52 udev
drwxr-xr-x  2 root root    4096 10月  5 03:41 w3m
drwxr-xr-x  2 root root    4096 10月  5 03:50 wpa_supplicant
drwxr-xr-x  4 root root    4096 10月  5 03:42 xdg
drwxr-xr-x  2 root root    4096 10月  5 04:02 xinetd.d
drwxr-xr-x  2 root root    4096 10月  5 03:59 xml
drwxr-xr-x  3 root root    4096 10月  5 03:59 yum
drwxr-xr-x  2 root root    4096  4月  4  2007 yum.repos.d
[root@localhost etc]#

『ログイン時,全てのユーザーに参照される』

[root@localhost ~]# ls -l /etc/profile
-rw-r--r-- 1 root root 937 11月 10 03:12 /etc/profile
基本的な環境変数などの設定をします。

===================================================

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
        EUID=`id -u`
        UID=`id -ru`
fi
HOSTNAME=`/bin/hostname`
HISTSIZE=3000
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done

unset i
===================================================

[root@localhost ~]# ls -l /etc/bashrc
-rw-r--r-- 1 root root 1437 11月 28  2006 /etc/bashrc
[root@localhost ~]#

 

===================================================

if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
        umask 002
else
        umask 022
fi
if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
        # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
                if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
                        if [ "$2" = "after" ] ; then
                                PATH=$PATH:$1
                        else
                                PATH=$1:$PATH
                        fi
                fi
        }

        for i in /etc/profile.d/*.sh; do
                if [ -r "$i" ]; then
                        . $i
        fi
        done
        unset i
        unset pathmunge
fi
===================================================

 

『ログイン時にユーザーHOMEディレクトリーのファイルが参照される』

[root@localhost ~]# ls -l /home/admin/.bash_profile
-rw-r--r-- 1 admin admin 219 10月  8 01:58 /home/admin/.bash_profile
===================================================

[root@localhost ~]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/bin/:/usr/sbin:/sbin:/usr/local/mysql

export PATH
[root@localhost ~]#
===================================================

 

[root@localhost ~]# ls -l /home/admin/.bashrc
-rw-r--r-- 1 admin admin 124  1月  6  2007 /home/admin/.bashrc

ファイルのコピー,削除,移動などをする時に確認メッセージを表示したい時は以下のようにラインを追加。

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
===================================================

[root@localhost ~]# more .bashrc
# .bashrc

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
[root@localhost ~]#

===================================================


[root@localhost ~]# ls -l /home/admin/.bash_logout
-rw-r--r-- 1 admin admin 24  1月  6  2007 /home/admin/.bash_logout
[root@localhost ~]#
===================================================

[root@localhost ~]# cat .bash_logout
# ~/.bash_logout

clear
[root@localhost ~]#
===================================================

 

[root@localhost ~]# ls -l .bash_history
-rw------- 1 admin admin 19973 11月 10 03:21 .bash_history
[root@localhost ~]#

bashコマンドの履歴
===================================================

[root@localhost ~]# more .bash_history
cd ..
cd /usr/local/src/
ls
cd php-5.2.4
ls
make test
ls
make clean
===================================================

~/.bash_login , ~/.profile , ~/.inputrcなどもあります。

 

 2574 pts/0    Ss     0:00 -bash  <--ログインシェル
 2616 pts/0    S      0:00 /bin/bash
 2720 pts/0    R+     0:00 ps awx

aliasコマンド.jpg
[root@localhost ~]# alias ls='ls -al'

[root@localhost ~]# ls
合計 22520
drwx------ 21 admin admin     4096 11月  5 00:11 .
drwxr-xr-x  7 root  root      4096 10月 14 18:41 ..

[root@localhost ~]# \ls
Desktop      atmarkit5th.tar.tar        mysql-5.0.22-2.1.src.rpm  source
atmarkit5th  mysql-5.0.22-2.1.i386.rpm  postsource

[root@localhost ~]# ls
合計 22520
drwx------ 21 admin admin     4096 11月  5 00:11 .
drwxr-xr-x  7 root  root      4096 10月 14 18:41 ..
-rw-------  1 admin admin      189 10月  4 21:11 .ICEauthority
drwx------  2 admin admin     4096 10月  4 21:11 .Trash
drwx------  2 admin admin     4096 10月  4 21:11 .anthy

 

メンテナンスのお知らせ。(緊急なときは,shutdown -kなど)

[root@localhost ~]# vi /etc/motdを編集するとユーザーがログインした時に,

メンテナンス等のアナウンスを出すことが出来る。


 

motd.jpgホストへアクセスした時のメッセー時について。

[root@localhost ~]# vi /etc/issue
[root@localhost ~]# vi /etc/issue.net
[root@localhost ~]# cat /etc/issue
CentOS release 5 (Final)
Kernel \r on an \m

[root@localhost ~]# cat /etc/issue.net
CentOS release 5 (Final)
Kernel \r on an \m
[root@localhost ~]#


/etc/issueに記述できるシーケンスとその意味

シーケンス
説明
  \d 日付を表示
  \l 仮想コンソールの番号を表示
  \m マシン(ハードウェア)タイプを表示
  \n ホスト名を表示
  \o ドメイン名を表示
  \r OSのリリースを表示
  \t 現在の時刻を表示
  \s OSの名前を表示
  \u ログインしているユーザー数を表示
  \U ログインしているユーザー数を「x users」と表示(「x」はユーザー数)
  \v OSのバージョンを表示

/etc/issue.netに記述できるシーケンスとその意味

シーケンス
説明
  %t 現在のtty(端末名)を表示
  %h システムのノード名(FQDN)を表示
  %D ドメイン名を表示
  %d 現在の時刻と日付を表示
  %s OSの名前を表示
  %m マシン(ハードウェア)タイプを表示
  %r OSのリリースを表示
  %v OSのバージョンを表示
  %% 1個の%文字を表示

 

1 ユーザーコマンド

2 システムコール

3 ライブラリ

4 デバイスファイル

5 ファイルフォーマット

6 ゲーム

7 その他

8 システム管理コマンド

9 Linux関連カーネル用ドキュメント

[root@localhost ~]# man 5 passwd

-a で全てのマニュアルページを参照

[root@localhost ~]# man -a passwd

man -f = whatis
[root@localhost ~]# whatis crontab
crontab              (1)  - maintain crontab files for individual users (ISC Cron V4.1)
crontab              (1p)  - schedule periodic background work
crontab              (5)  - tables for driving cron (ISC Cron V4.1)
[root@localhost ~]#

 

-kコマンドでコマンドを部分的に忘れていてもコマンド一覧を出してくれる。

[root@localhost ~]# man -k cron
anacron              (8)  - runs commands periodically
anacron             (rpm) - A cron-like program that can run jobs lost during downtime.
cron                 (8)  - daemon to execute scheduled commands (ISC Cron V4.1)
crontab              (1)  - maintain crontab files for individual users (ISC Cron V4.1)
crontab              (1p)  - schedule periodic background work
crontab              (5)  - tables for driving cron (ISC Cron V4.1)
crontabs            (rpm) - Root crontab files used to schedule the execution of programs.

apropos = man -k xxxx

[root@localhost ~]# apropos cron
anacron              (8)  - runs commands periodically
anacron             (rpm) - A cron-like program that can run jobs lost during downtime.
cron                 (8)  - daemon to execute scheduled commands (ISC Cron V4.1)
crontab              (1)  - maintain crontab files for individual users (ISC Cron V4.1)
crontab              (1p)  - schedule periodic background work
crontab              (5)  - tables for driving cron (ISC Cron V4.1)
crontabs            (rpm) - Root crontab files used to schedule the execution of programs.

infoコマンド

[root@localhost ~]# info shuttdown

whichコマンドでパスを見付ける
[root@localhost ~]# which bash
/bin/bash

whichコマンド応用

[root@localhost ~]# rpm -qf `which bash`
bash-3.1-16.1
[root@localhost ~]# rpm -qf `which mysql`
mysql-5.0.22-2.1.0.1

whereisコマンド

-m マニュアルを検索

-b バイナリーファイルを検索

-s ソースファイルを検索

[root@localhost ~]# whereis -m ifconfig
ifconfig: /usr/share/man/man8/ifconfig.8.gz
[root@localhost ~]# whereis -b ifconfig
ifconfig: /sbin/ifconfig

このアーカイブについて

このページには、2007年11月に書かれたブログ記事が新しい順に公開されています。

前のアーカイブは2007年10月です。

次のアーカイブは2007年12月です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

Powered by Movable Type 4.0