#!/bin/bash
MAILDIR=/home/mailtest/mail
PERSISTENCE_FILE=/tmp/mailnum

cur_num=$(find $MAILDIR -type f | wc -l)
prev_num=$(cat $PERSISTENCE_FILE)

EXITCODE=3
STATUS=UNKNOWN

if [ "$cur_num" -gt "$prev_num" ]; then
    EXITCODE=0
    STATUS="OK: increasing"
else
    EXITCODE=1
    STATUS="CRITICAL: not increasing"
fi

echo $cur_num > $PERSISTENCE_FILE

performance="mails=$cur_num"

echo "$STATUS |$performance"
exit $EXITCODE
    
