Difference between revisions of "HowTos/AdminScripts"

From Scalix Wiki
Jump to: navigation, search
(reset the imap-cache for a mailbox)
(reset the imap-cache for a mailbox)
Line 49: Line 49:
 
     echo "locking mail-account ..."
 
     echo "locking mail-account ..."
 
     /opt/scalix/bin/ommodu -o "$1" -K
 
     /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 ..."
 
     echo "removing $REALPATH$FOLDER/imap-cache ..."
 
     rm -rf  $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)"                                                                                                                     
 
     echo -n "do you want to recreate the mailboxcache for $1 which can take a while (y/N)"                                                                                                                     
 
     read DOIT2
 
     read DOIT2
 
     if [ "$DOIT2" = "y" ]
 
     if [ "$DOIT2" = "y" ]
 
     then
 
     then
 +
        echo "killing UAL-remote processes for user $1 (uid $ID) ..."
 +
        pkill -u $ID ual.remote
 +
        echo "removing $REALPATH$FOLDER/00000v8.ofs ..."
 +
        rm -rf  $REALPATH$FOLDER/00000v8.ofs
 
         echo "recreating mailboxcache for $1...."
 
         echo "recreating mailboxcache for $1...."
 
         /opt/scalix/bin/sxmbcprep -B -u "$1"
 
         /opt/scalix/bin/sxmbcprep -B -u "$1"
 
     fi
 
     fi
 +
    echo "unlocking mail-account ..."
 
     /opt/scalix/bin/ommodu -o "$1" -k
 
     /opt/scalix/bin/ommodu -o "$1" -k
 
     echo "done!"
 
     echo "done!"

Revision as of 14:57, 1 August 2007

Here are some scripts that aren't big enough for a own topic.

show the g-directory of a specific user

Sometimes we have to know the g-directory of a mailbox. If you don't want to deal with omshowu every time you can use this script:

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

As we are using the command "omshowu", we can use the same syntax to specify the username.

You can try to use the script like this:

cd `name_of_script "Givenname Surname"`

reset the imap-cache for a mailbox

A logical follow-up from the script above. With some early Scalix 11 versions it might necessary to reset the imap-cache.

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 "removing $REALPATH$FOLDER/imap-cache ..."
    rm -rf  $REALPATH$FOLDER/imap-cache
    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 "killing UAL-remote processes for user $1 (uid $ID) ..."
        pkill -u $ID ual.remote
        echo "removing $REALPATH$FOLDER/00000v8.ofs ..."
        rm -rf  $REALPATH$FOLDER/00000v8.ofs
        echo "recreating mailboxcache for $1...."
        /opt/scalix/bin/sxmbcprep -B -u "$1"
    fi
    echo "unlocking mail-account ..."
    /opt/scalix/bin/ommodu -o "$1" -k
    echo "done!"
  fi
else
  echo "Can not find $1"
fi

script to fill mailboxes

if you have any reason to need a full mailbox, for example to test a backup system, this script can deliver.

#!/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

script to genererate login statistics

this script will parse your audit logs and generate a nicely formatted breakdown of the logins on your system.

you'll need to set up auditing on the appropriate services, check out omshowaud and omconfaud to do that.

#!/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

and this is what it generates, isn't that cute? it took much longer to get the printf stuff together than the script itself...


|-----------------------------------------------|
| 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        |
|-----------------------------------------------|

scripts to stow queue state

these are very simple scripts to programatically retrieve statistics on queue status. i like to build them into monitoring scripts and pipe them to mail

#!/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"