Initial import
This commit is contained in:
102
sent_userinfo_postfix.sh
Executable file
102
sent_userinfo_postfix.sh
Executable file
@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
user_info_file="/root/Heartbleed-Bug_userinfo.txt"
|
||||
|
||||
email_from="oo@oopen.de"
|
||||
|
||||
mail_user=vmail
|
||||
mail_group=vmail
|
||||
|
||||
mail_basedir=/var/vmail
|
||||
|
||||
logfile=/tmp/user_mail.log
|
||||
> $logfile
|
||||
|
||||
|
||||
curdir=`pwd`
|
||||
rc_done="\033[71G[ \033[32mdone\033[m ]"
|
||||
rc_failed="\033[71G[ \033[31m\033[1mfailed\033[m ]"
|
||||
|
||||
|
||||
## - Functions
|
||||
## -
|
||||
echononl(){
|
||||
echo X\\c > /tmp/shprompt$$
|
||||
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||
echo "$*\\c" 1>&2
|
||||
else
|
||||
echo -e -n "$*" 1>&2
|
||||
fi
|
||||
rm /tmp/shprompt$$
|
||||
}
|
||||
|
||||
|
||||
fatal(){
|
||||
echo ""
|
||||
echo Fehler: $*
|
||||
echo -e "\n\t\033[31m\033[1mSkript wird abgebrochen\033[m\033[m\n"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
## -
|
||||
## - End: Functions
|
||||
|
||||
if [ ! -f $user_info_file ]; then
|
||||
fatal "Kann Mailtext nicht finden"
|
||||
fi
|
||||
|
||||
pwd=`pwd`
|
||||
cd /tmp
|
||||
|
||||
clear
|
||||
echo -e "\n\t --- Sending userinfo into all local virtual mailboxes --\n" | tee -a $logfile
|
||||
|
||||
if [ ! -f $user_info_file ];then
|
||||
echo "[FATAL]: Info-file to send does not exist !!" >> $logfile
|
||||
fatal "User Info-file to send does not exist !!"
|
||||
fi
|
||||
|
||||
|
||||
## - list of local virtual domains
|
||||
## -
|
||||
domains=`su postgres -c"psql -At -F ' ' postfix -c\"SELECT domain FROM domain WHERE domain != 'ALL' ORDER BY domain\""`
|
||||
|
||||
declare -i num_dom=0;
|
||||
declare -i num_mbox_failed=0;
|
||||
declare -i num_mbox=0;
|
||||
|
||||
for domain in $domains ;do
|
||||
echo -e "\nDOMAIN: $domain\n" | tee -a $logfile
|
||||
local_parts=`su postgres -c"psql -At -F ' ' postfix -c\"SELECT local_part FROM mailbox WHERE domain = '$domain'\""`
|
||||
for local_part in $local_parts ; do
|
||||
cp $user_info_file /tmp/
|
||||
perl -i -n -p -e "s/%email_to%/$local_part\@$domain/" /tmp/`basename $user_info_file`
|
||||
echononl "\tSend userinfo to $local_part@$domain.."
|
||||
cat /tmp/`basename $user_info_file` | /usr/sbin/sendmail -F 'Christoph Kuchenbuch' -f $email_from -t "$local_part@$domain"
|
||||
if [ "$?" = "0" ]; then
|
||||
num_mbox=num_mbox+1
|
||||
echo -e "$rc_done"
|
||||
else
|
||||
echo -e "$rc_failed"
|
||||
echo " [ERROR]: Cannot sent userinfo to \"$local_part\@$domain\"!" >> $logfile
|
||||
num_mbox_failed=num_mbox_failed+1
|
||||
fi
|
||||
done
|
||||
num_dom=num_dom+1
|
||||
done
|
||||
|
||||
echo -e "\n\n----- Statistics -----\n\n\tSent mail to $num_mbox mailboxe(s) of $num_dom domain(s)" | tee -a $logfile
|
||||
|
||||
if [ $num_mbox_failed -gt 0 ];then
|
||||
echo -e "\n\tFailed sending mail to $num_mbox_failed mailboxe(s)" >> $logfile
|
||||
echo -e "\n\t\033[31m\033[1mFailed sending mail to $num_mbox_failed mailboxe(s)\033[m\033[m"
|
||||
echo -e "\n\n-- See $logfile for details\n" | tee -a $logfile
|
||||
fi
|
||||
|
||||
echo
|
||||
cd $pwd
|
||||
rm /tmp/`basename $user_info_file`
|
||||
|
||||
exit
|
Reference in New Issue
Block a user