« swap ファイル追加手順 | メイン | UnixScriptTools for mi »

2006年1月 6日

logadm(1M) でのログローテーション実行コマンドについて

Solaris 8 までの OS では、messages や syslog ファイルのローテーションは
/usr/lib/newsyslog スクリプトにより mv を行って、/dev/null を cp していた。
Solaris 9 からは (logadm を使用した場合には) どのようなコマンドが実行されのか?

■ /usr/lib/newsyslog スクリプト
:
LOG=messages
cd /var/adm
test -f $LOG.2 && mv $LOG.2 $LOG.3
test -f $LOG.1 && mv $LOG.1 $LOG.2
test -f $LOG.0 && mv $LOG.0 $LOG.1
mv $LOG $LOG.0
cp /dev/null $LOG
chmod 644 $LOG
:

──────────────────


logadm コマンドの -n オプションでローテーションのアクションを標準出力させることができ、その結果より実行コマンドを確認することが可能。
最後に実施結果を添付。

■ man logadm より抜粋

-n Print the actions that the logadm command will perform
without actually performing them.

This option is useful for checking arguments before
making any changes to the system.

It is important to remember, however, that since log
rotating actions are only printed with this option,
logadm might not find files that need expiring, but if
run without the -n logadm might create a file that
needs expiring by performing the log rotating actions.
Therefore, if you see no files being expired with the
-n option, files still might be expired without it.

■ logadm -n の実行結果

# logadm -n /var/log/syslog -p now
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.7 /var/log/syslog.8 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.6 /var/log/syslog.7 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.5 /var/log/syslog.6 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.4 /var/log/syslog.5 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.3 /var/log/syslog.4 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.2 /var/log/syslog.3 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.1 /var/log/syslog.2 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog.0 /var/log/syslog.1 # rotate log file
mkdir -p /var/log # verify directory exists
mv -f /var/log/syslog /var/log/syslog.0 # rotate log file
touch /var/log/syslog
chown 0:3 /var/log/syslog
chmod 644 /var/log/syslog
sh -c kill -HUP `cat /var/run/syslog.pid` # -a cmd
#

投稿者 AJ : 2006年1月 6日 10:00

トラックバック

このエントリーのトラックバックURL:
http://www.factory-aj.com/cgi/mtctrl/mt-tb.cgi/204

 
Powered by Movable Type 4.27-ja | RSS1.0 | RSS2.0 | ATOM