add icinga downtime scheduling script, add whois script, optimize mailbox usage

This commit is contained in:
Oliver Ladner 2018-08-22 23:07:28 +02:00
commit 6c054f63ca
3 changed files with 92 additions and 3 deletions

44
icinga_downtime.sh Normal file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env bash
#
# Schedule a custom downtime
icinga_user="FIXME"
icinga_pw="FIXME"
cgi_path="https://example.org/icinga/cgi-bin/cmd.cgi?"
commandfile='/var/spool/icinga/cmd/icinga.cmd'
if [ -z $1 ]; then $0 -h; exit 1; fi
while getopts ":s:d:h" opt; do
case $opt in
s)
tmp=$(echo "$OPTARG" | sed 's/,/ /g')
vm=($tmp) # convert $tmp to array
;;
d)
duration=$OPTARG
;;
h)
echo "Usage: $(basename $0) -s VM1[,VM2] -d DURATION IN SECONDS"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
now=$(date +%s)
now_h=$(date -d @$now +"%m-%d-%Y %H:%M:%S")
to=$(($now+$duration))
to_h=$(date -d @$to +"%m-%d-%Y %H:%M:%S")
for system in "${vm[@]}"; do
url="fixed=1&cmd_typ=86&cmd_mod=2&start_time=$now_h&end_time=$to_h&host=$system&com_author=FIXME&com_data=Automated%20downtime&btnSubmit=Commit"
$(which curl) -v -u "$icinga_user":"$icinga_pw" "$cgi_path" -d "$url"
done

View file

@ -5,12 +5,39 @@
# Lists mailbox size of all virtual users
# of all domains
PER_USER="/var/vmail/*.*/*"
PER_DOMAIN="/var/vmail/*.*/"
TOTAL="/var/vmail/"
MAILDIR="/var/vmail"
PER_USER="$MAILDIR/*.*/*"
PER_DOMAIN="$MAILDIR/*.*/"
TOTAL="$MAILDIR"
TRASHDIR="$MAILDIR/*.*/*/Maildir/.Trash/*/"
SPAMDIR="$MAILDIR/*.*/*/Maildir/.spam/*/"
DRAFTSDIR="$MAILDIR/*.*/*/Maildir/.Drafts/*/"
SENTDIR="$MAILDIR/*.*/*/Maildir/.Sent/*/"
echo "Per User"
du -hs $PER_USER | sort -rh | awk -F"/" '{print $1,$5,"@"$4}' | sed 's/ @/@/g'
echo -e "\r"
echo "Per Domain"
du -hs $PER_DOMAIN | sort -rh | awk -F"/" '{print $1,$4}'
echo -e "\r"
echo "Trash Folders"
du -hs $TRASHDIR | sort -rh | awk -F"/" '{print $1,$5,"@"$4}' | sed 's/ @/@/g' | grep -v "4.0K" | grep -v "8.0K"
echo -e "\r"
echo "Spam Folders"
du -hs $SPAMDIR | sort -rh | awk -F"/" '{print $1,$5,"@"$4}' | sed 's/ @/@/g' | grep -v "4.0K" | grep -v "8.0K"
echo -e "\r"
echo "Drafts Folders"
du -hs $DRAFTSDIR | sort -rh | awk -F"/" '{print $1,$5,"@"$4}' | sed 's/ @/@/g' | grep -v "4.0K" | grep -v "8.0K"
echo -e "\r"
echo "Sent Folders"
du -hs $SENTDIR | sort -rh | awk -F"/" '{print $1,$5,"@"$4}' | sed 's/ @/@/g' | grep -v "4.0K" | grep -v "8.0K"
echo -e "\r"
echo "Total"
du -hs $TOTAL

18
whois.sh Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
#
# Checks if the specific domain is available
domain=$1
check=$(whois -h whois.nic.ch -p 4343 $domain | head -1 | awk -F':' {'print $1'})
case "$check" in
0)
# already registered
;;
1)
echo "free!" | mail -s "$domain is free!" oli@lugh.ch ;;
*)
echo "unhandled, see https://www.nic.ch/reg/cm/wcm-page/faqs/technical/whoisis.jsp" ;;
esac