sort の -k オプション


IMG_0019



※写真と本文は関係ありません。


qmailanalog(http://cr.yp.to/qmailanalog.html

こちらを参考にさせていただいて、インストール。

古いシステムだと行けたんですが、新しいとちゃんとログ集計が出来ない…。


スクリプトのカラムでソートのオプションが『 +2 』から『 -k 2 』に変更されてた。

ダメなほうの man を見ると 『 -k 』のほうが推奨されてるのでなくなる運命だったみたい。


新しい(ダメだった)『 sort 』のVersion


[root@sv qmailanalog-0.70]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.1 (Tikanga)
 
[root@sv qmailanalog-0.70]# sort --version
sort (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.
 
Written by Mike Haertel and Paul Eggert.


古い『 sort 』のVersion


[root@ws1 root]# cat /etc/vine-release 
Vine Linux 3.1 (Pichon Lalande)
 
[anaheim@ws1 anaheim]$ sort --version
sort (textutils) 2.0.17
作者 Mike Haertel and Paul Eggert.
 
Copyright (C) 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



Vine のメーリングリストに似たものが…。
http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=490

で、patch を書いた。展開したディレクトリで、『 $ patch -p1 < sort.patch 』する。


[root@sv1 qmailanalog]$ cat sort.patch 
diff -Nur qmailanalog-0.70_org/zdeferrals.sh qmailanalog-0.70_patched/zdeferrals.sh
--- qmailanalog-0.70_org/zdeferrals.sh  2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zdeferrals.sh  2009-09-25 14:27:30.000000000 +0900
@@ -5,4 +5,4 @@
 * xdelay is the total xdelay on those deliveries.
 '
 ( echo del xdelay reason
-HOME/bin/deferrals | sort +2 ) | HOME/bin/columnt | tr _ ' '
+HOME/bin/deferrals | sort -k 2 ) | HOME/bin/columnt | tr _ ' '
diff -Nur qmailanalog-0.70_org/zfailures.sh qmailanalog-0.70_patched/zfailures.sh
--- qmailanalog-0.70_org/zfailures.sh   2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zfailures.sh   2009-09-25 14:27:47.000000000 +0900
@@ -5,4 +5,4 @@
 * xdelay is the total xdelay on those deliveries.
 '
 ( echo del xdelay reason
-HOME/bin/failures | sort +2 ) | HOME/bin/columnt | tr _ ' '
+HOME/bin/failures | sort -k 2 ) | HOME/bin/columnt | tr _ ' '
diff -Nur qmailanalog-0.70_org/zrecipients.sh qmailanalog-0.70_patched/zrecipients.sh
--- qmailanalog-0.70_org/zrecipients.sh 2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zrecipients.sh 2009-09-25 14:28:09.000000000 +0900
@@ -7,4 +7,4 @@
 * xdelay is the total xdelay incurred by this recipient.
 '
 ( echo sbytes mess tries xdelay recipient
-HOME/bin/recipients | sort +4 ) | HOME/bin/columnt
+HOME/bin/recipients | sort -k 4 ) | HOME/bin/columnt
diff -Nur qmailanalog-0.70_org/zrhosts.sh qmailanalog-0.70_patched/zrhosts.sh
--- qmailanalog-0.70_org/zrhosts.sh 2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zrhosts.sh 2009-09-25 14:28:27.000000000 +0900
@@ -7,4 +7,4 @@
 * xdelay is the total xdelay incurred by this host.
 '
 ( echo sbytes mess tries xdelay host
-HOME/bin/rhosts | sort +4 ) | HOME/bin/columnt
+HOME/bin/rhosts | sort -k 4 ) | HOME/bin/columnt
diff -Nur qmailanalog-0.70_org/zsenders.sh qmailanalog-0.70_patched/zsenders.sh
--- qmailanalog-0.70_org/zsenders.sh    2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zsenders.sh    2009-09-25 14:29:25.000000000 +0900
@@ -10,4 +10,4 @@
 * xdelay is the total xdelay incurred by this sender.
 '
 ( echo mess bytes sbytes rbytes recips tries xdelay sender
-HOME/bin/senders | sort -n +7 ) | HOME/bin/columnt
+HOME/bin/senders | sort -n -k 7 ) | HOME/bin/columnt
diff -Nur qmailanalog-0.70_org/zsuccesses.sh qmailanalog-0.70_patched/zsuccesses.sh
--- qmailanalog-0.70_org/zsuccesses.sh  2009-09-25 16:55:56.000000000 +0900
+++ qmailanalog-0.70_patched/zsuccesses.sh  2009-09-25 14:34:49.000000000 +0900
@@ -5,4 +5,4 @@
 * xdelay is the total xdelay on those deliveries.
 '
 ( echo del xdelay reason
-HOME/bin/successes | sort +2 ) | HOME/bin/columnt | tr _ ' '
+HOME/bin/successes | sort -k 2 ) | HOME/bin/columnt | tr _ ' '
diff -Nur qmailanalog-0.70_org/zsuids.sh qmailanalog-0.70_patched/zsuids.sh
--- qmailanalog-0.70_org/zsuids.sh  2009-09-25 16:56:10.000000000 +0900
+++ qmailanalog-0.70_patched/zsuids.sh  2009-09-25 14:29:44.000000000 +0900
@@ -10,4 +10,4 @@
 * xdelay is the total xdelay incurred by this uid.
 '
 ( echo mess bytes sbytes rbytes recips tries xdelay uid
-HOME/bin/suids | sort -n +7 ) | HOME/bin/columnt
+HOME/bin/suids | sort -n -k 7 ) | HOME/bin/columnt



[root@sv2012 qmailanalog-0.70]# cat /etc/cron.daily/qmailanalog 
#!/bin/sh
PATH=$PATH:/usr/local/qmailanalog/bin:/var/qmail/bin
LANG=C
MAILLOG=`mktemp /tmp/tmp.XXXXXX`
QMAILLOG=`mktemp /tmp/tmp.XXXXXX`
QMAILREPORT=`mktemp /tmp/tmp.XXXXXX`
# 統計対象設定
# 不要な場合はコメントアウトする
zoverall=1 # 基本統計
#zddist=1 # メール遅送の集計
zdeferrals=1 # deferrals(配送が先延ばし)されたときの理由の集計
zfailures=1 # 失敗メールの理由
zrecipients=1 # 受け取り先の集計
#zrxdelay=1 # 受け取り先の集計(遅れ具合でソート)
zsenders=1 # 差し出し元の集計
zsuids=1 # 差し出し元のUID集計
zrhosts=1 # 相手のホストの集計
# 統計出力用関数宣言
report(){
    echo "---------------------------------------------------" >> $QMAILREPORT
    $1 2>/dev/null < $QMAILLOG >> $QMAILREPORT
    echo "---------------------------------------------------" >> $QMAILREPORT
    echo "" >> $QMAILREPORT
}
# 前日分のログを抽出してqmailanalog向けに整形
grep ^"`date --date '1 days ago' +'%b %_d'`" /var/log/maillog.1 >> $MAILLOG
grep ^"`date --date '1 days ago' +'%b %_d'`" /var/log/maillog >> $MAILLOG
awk '{$1="";$2="";$3="";$4="";$5="";print}' < $MAILLOG | matchup > $QMAILLOG 5> /dev/null
# タイトル出力
echo "====================================================" >> $QMAILREPORT
echo "qmail statistics from qmailanalog" >> $QMAILREPORT
echo "Report Date: `date --date '1 days ago' +'%Y/%m/%d(%a)'`" >> $QMAILREPORT
echo "====================================================" >> $QMAILREPORT
echo "" >> $QMAILREPORT
# 各種統計出力
[ "$zoverall" = "1" ] && report zoverall
[ "$zddist" = "1" ] && report zddist
[ "$zdeferrals" = "1" ] && report zdeferrals
[ "$zfailures" = "1" ] && report zfailures
[ "$zrecipients" = "1" ] && report zrecipients
[ "$zrxdelay" = "1" ] && report zrxdelay
[ "$zsenders" = "1" ] && report zsenders
[ "$zsuids" = "1" ] && report zsuids
[ "$zrhosts" = "1" ] && report zrhosts
# 出力結果をpostmaster宛にメール送信
mail -s "qmail statistics" postmaster@`hostname -d` < $QMAILREPORT
#cat $QMAILLOG
#cat $QMAILREPORT
#echo $MAILLOG
#echo $QMAILLOG
#echo $QMAILREPORT
#zfailures  < "$QMAILLOG"
# 一時ファイル削除(後始末)
rm -f $MAILLOG $QMAILLOG $QMAILREPORT


64bitだとmakeでエラー


/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in strerr.a(strerr_sys.o)
/lib64/libc.so.6: could not read symbols: Bad value
collect2: ld はステータス 1 で終了しました
make: *** [matchup] エラー 1


こんな感じに修正。


$ cat  conf-cc
cc -O2
This will be used to compile .c files.
$ cp conf-cc conf-cc_org
$ echo "gcc -O2 --include /usr/include/errno.h" > conf-cc