Postfix ip rotation bash style

[root@mx12 postfix]# pwd
/etc/postfix

[root@mx12 postfix]# touch current.txt &&  vim  bal.cf

#!/bin/bash
ips=("5.9.240.232" "5.9.219.160" "5.9.219.166" "5.9.219.167")
length=${#ips[@]}
pos=`cat current.txt`
oldip=${ips[$pos - 1]}
if [ "$length" -eq "$pos" ] ; then
    echo "limit reached"
    pos=1
else
    echo "increment!"
    (( pos++ ))
fi

echo "$pos" > current.txt

newip=${ips[$pos - 1]}
echo "prev: $oldip"
echo "new: $newip"
echo "=============="
sed -ie "s/smtp_bind_address=$oldip/smtp_bind_address=$newip/g" /etc/postfix/main.cf > /dev/null
service MailScanner restart


[root@mx12 postfix]# cat current.txt
1

put the script bal.cf in crontab to run every  5 or 10 or 15 so...........


No comments:

Post a Comment