HowTos/管理スクリプト
出典: ScalixWikiJP
Scalix Wiki -> How-Tos -> HowTos/管理スクリプト
このセクションは HowTos/AdminScripts(米国サイト)をもとに作成しています。
ここには管理者が利用できる数々のスクリプトが記述されています。
目次 |
特定のユーザの g ディレクトリを表示する
omshowu コマンドについて詳しくなくても、このスクリプトを使ってメールボックスの g ディレクトリを表示させることができます。
if [ "$1" = "" ]
then
echo "usage: $0 username"
exit 1
fi
REALPATH=`/opt/scalix/bin/omrealpath "~/"`
OMSHOWU=`/opt/scalix/bin/omshowu -n "$1" -f 2>/dev/null| grep "User Folder"`
if [ $? -eq 0 ]
then
FOLDER=`echo $OMSHOWU | awk -F/ '{print $2 "/" $3 }' `
echo $REALPATH$FOLDER
else
echo "Can not find $1"
fi
"omshowu" コマンドを使用する場合と同じシンタックスでユーザ名を指定できます。
このスクリプトは次のように使用できます:
cd `スクリプト名 "Givenname Surname"`
メールボックスのIMAP キャッシュをリセットする
上記のスクリプトのロジックを応用します。 Scalix 11 の前の方のバージョンでは、IMAPキャッシュをリセットすることが必要です。
if [ "$1" = "" ]
then
echo "usage: $0 username"
exit 1
fi
REALPATH=`/opt/scalix/bin/omrealpath "~/"`
OMSHOWU=`/opt/scalix/bin/omshowu -n "$1" -f 2>/dev/null| grep "User Folder"`
if [ $? -eq 0 ]
then
FOLDER=`echo $OMSHOWU | awk -F/ '{print $2 "/" $3 }' `
ID=`/opt/scalix/bin/omshowu -n "$1" | grep "System Login :" | awk -F: '{print $2}' `
echo -n "Do you really want to remove the imap-cache for $1 (y/N)"
read DOIT
if [ "$DOIT" = "y" ]
then
echo "killing IMAP-processes for user $1 (uid $ID) ..."
pkill -u $ID in.imap41d
echo "locking mail-account ..."
/opt/scalix/bin/ommodu -o "$1" -K
echo "killing UAL-remote processes for user $1 (uid $ID) ..."
pkill -u $ID ual.remote
echo "removing $REALPATH$FOLDER/imap-cache ..."
rm -rf $REALPATH$FOLDER/imap-cache
echo "removing $REALPATH$FOLDER/00000v8.ofs ..."
rm -rf $REALPATH$FOLDER/00000v8.ofs
echo "unlocking mail-account ..."
echo -n "do you want to recreate the mailboxcache for $1 which can take a while (y/N)"
read DOIT2
if [ "$DOIT2" = "y" ]
then
echo "recreating mailboxcache for $1...."
/opt/scalix/bin/sxmbcprep -B -u "$1"
fi
/opt/scalix/bin/ommodu -o "$1" -k
echo "done!"
fi
else
echo "Can not find $1"
fi
メールボックスにメッセージを蓄える
バックアップシステムのテストなどでメールボックスにメッセージを大量に蓄える必要があるとき、このスクリプトが利用できます。
注意:ユーザ名にスペースが入るときは、ユーザ名を " で囲う、など変更してください。
#!/bin/bash
#fillbox.sh
#cmeid, jan07
#global varz
#these must be changed
fromUser=tester
fromPass=password
toUser=cmeid
#if you want to use carbon copy and/or bcc, be sure to uncomment the appropriate lines below
#copyUser=
#bccUser=
#these should be acceptable defaults
dataFile=rawdatafile
dataSize=15k
subject="Test Mail"
bodyFile=rawbodyfile
bodySize=1k
messageCount=1000
displayIncrement=50
#no sanity checking. only for use on trusted systems!!!
#init attachments/bodymessages
if [ ${bodySize} != 0 ]; then
dd bs=${bodySize} count=1 if=/dev/urandom of=${bodyFile}.tmp &>/dev/null
cat ${bodyFile}.tmp | uuencode -m ${bodyFile} > ${bodyFile}
rm ${bodyFile}.tmp
fi
if [ ${dataSize} != 0 ]; then
dd bs=${dataSize} count=1 if=/dev/urandom of=${dataFile} &>/dev/null
fi
#set up looping, go get a coffee and have a smoke
i=1
echo ""
echo -n Sending email ...
until [ ${i} -gt ${messageCount} ]; do
if [ ${dataSize} = 0 ] ; then
# omsend -q -u ${fromUser} -p ${fromPass} -s "${subject} ${i} from ${fromUser} body size ${bodySize}" -t ${toUser} -c ${copyUser} -b ${bccUser} -a ${bodyFile}
omsend -q -u ${fromUser} -p ${fromPass} -s "${subject} ${i} from ${fromUser} body size ${bodySize}" -t ${toUser} -a ${bodyFile}
else
# omsend -q -u ${fromUser} -p ${fromPass} -s "${subject} ${i} from ${fromUser} bodysize ${bodySize}i datasize ${dataSize}" -t ${toUser} -c ${copyUser} -b ${bccUser} -a ${bodyFile} -r ${dataFile}
omsend -q -u ${fromUser} -p ${fromPass} -s "${subject} ${i} from ${fromUser} bodysize ${bodySize}i datasize ${dataSize}" -t ${toUser} -a ${bodyFile} -r ${dataFile}
fi
let i+=1
remainder=`expr ${i} % ${displayIncrement}`
if [ $remainder = 0 ]; then
echo ""
echo -n ${i} email sent.
else
echo -n .
fi
done
echo ""
echo Total `expr ${i} - 1` mails sent
echo $i
echo ""
exit 0
ログイン状況一覧を表示する
このスクリプトは、audit ログを解析し、システムへのログイン状況を表示するスクリプトです。 このスクリプトを使用する際には、あらかじめ audit ログに、ログインの記録が残るよう、omconfaud でログ出力レベルを設定をしておかなければなりません。 (IMAPサーバデーモンのログ出力レベルを 1 にする、など)
注意:日本語の環境の場合は、日付のパラメータが正しく設定されるように変更してください。(export today=`LANG=C date "+%a %b %d"` など)
#!/bin/bash
#logonstat.sh
#cmeid, 20070514
source /opt/scalix/global/config
export today=`date "+%a %b %d"`
#export today="Sun May 13"
declare -a times logons users
for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; do
#for i in 00 01; do
j=$(expr $i + 0)
times[$j]=$i
logons[$j]=`grep -A1 user-signon $OMDATADIR/logs/audit | grep "$today $i" | wc -l`
users[$j]=`grep -A6 user-signon $OMDATADIR/logs/audit | grep -A4 "$today $i"| grep user\ |awk '{print $((NF-1))}'|sort|uniq -c|wc -l`
done
tLogons=`grep -A1 user-signon $OMDATADIR/logs/audit | grep "$today" | wc -l`
tUsers=`grep -A6 user-signon $OMDATADIR/logs/audit | grep -A4 "$today"| grep user\ |awk '{print $((NF-1))}'|sort|uniq -c|wc -l`
function printemptycell() {
printf '|---------------'
}
function printcontent() {
printf '|'" "${times[$1]}-${times[$(($1+1))]}"\t"
printf '|'" "${users[$1]}"\t"
printf '|'" "${logons[$1]}"\t"
}
function printtotals() {
printf '|'" "00-24"\t"
printf '|'" "$tUsers"\t"
printf '|'" "$tLogons"\t"
}
function printdiv() {
printf '|'"\n"
i=1
while [ $i -le 3 ]; do
printemptycell
let "i+=1"
done
printf '|'"\n"
}
function printheader() {
printf '| '"$@\t"
}
function printborder() {
printf '|-----------------------------------------------|'"\n"
}
printf "\n"
printborder
printheader "Scalix Server `hostname --fqdn` Logins"
printdiv
printheader "Hour period"
printheader "Total Unique"
printheader "Total Logons"
printf '|'"\n"
printheader "Between"
printheader "Users Seen"
printheader "Handled"
printdiv
printtotals
k=1
while [ $k -lt ${#times[@]} ]; do
printdiv
printcontent $k
let "k+=1"
done
printf '|'"\n"
printborder
以下は、上記のスクリプトで出力される内容の例です。
|-----------------------------------------------| | Scalix Server scalix.your-server.de Logins | |---------------|---------------|---------------| | Hour period | Total Unique | Total Logons | | Between | Users Seen | Handled | |---------------|---------------|---------------| | 00-24 | 1072 | 20478 | |---------------|---------------|---------------| | 01-02 | 0 | 0 | |---------------|---------------|---------------| | 02-03 | 0 | 0 | |---------------|---------------|---------------| | 03-04 | 32 | 74 | |---------------|---------------|---------------| | 04-05 | 32 | 156 | |---------------|---------------|---------------| | 05-06 | 32 | 336 | |---------------|---------------|---------------| | 06-07 | 61 | 713 | |---------------|---------------|---------------| | 07-08 | 183 | 836 | |---------------|---------------|---------------| | 08-09 | 180 | 529 | |---------------|---------------|---------------| | 09-10 | 220 | 729 | |---------------|---------------|---------------| | 10-11 | 202 | 689 | |---------------|---------------|---------------| | 11-12 | 404 | 1421 | |---------------|---------------|---------------| | 12-13 | 502 | 2226 | |---------------|---------------|---------------| | 13-14 | 466 | 2150 | |---------------|---------------|---------------| | 14-15 | 468 | 2673 | |---------------|---------------|---------------| | 15-16 | 376 | 2132 | |---------------|---------------|---------------| | 16-17 | 202 | 1305 | |---------------|---------------|---------------| | 17-18 | 95 | 877 | |---------------|---------------|---------------| | 18-19 | 67 | 800 | |---------------|---------------|---------------| | 19-20 | 74 | 789 | |---------------|---------------|---------------| | 20-21 | 56 | 737 | |---------------|---------------|---------------| | 21-22 | 46 | 697 | |---------------|---------------|---------------| | 22-23 | 44 | 609 | |---------------|---------------|---------------| | 23- | 0 | 0 | |-----------------------------------------------|
キューの状態を表示する
これらは、キューの状態をチェックするスクリプトです。これらのスクリプトは監視用のスクリプトなどに取り込むとよいでしょう。
#!/bin/bash date echo -e "A$((`date +%d|sed -e's/^.*0//g'`+10))E\ns"|omqdump 2>/dev/null|sed -e '1,/Quit/ d' -e 's/Option?//g' -e 's/Done//g'|tr -s "\n"
#!/bin/bash date echo -e "A$((`date +%d|sed -e's/^.*0//g'`+10))E\nT"|omqdump 2>/dev/null|sed -e '1,/Quit/ d' -e 's/Option?//g' -e 's/Done//g'|tr -s "\n"
