Score:0

How to execute a bash script on every outbound email POSTFIX

pk flag

I have written an IP rotation shell script. The Script is given below.

#!/bin/sh

#Get the counter from stored value
read count < counter.txt

if [[ $count -eq 0 ]]
then
    prev=5
fi

if [[ $count -gt 0 ]]
then
    prev=$(($count-1))
fi

#First we want to store all available IP addresses
IP_ADDRESSES=(1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1)

#Store all hostnames
HOST_NAMES=(server1.example.com server2.example.com server3.example.com server4.example.com server5.example.com server6.example.com)
#this command will

#echo ${IP_ADDRESSES[$count]}

#now change system default source ip
ip route replace default via ${IP_ADDRESSES[$prev]} dev venet0 src ${IP_ADDRESSES[$count]}

#Now change the hostname
hostnamectl set-hostname ${HOST_NAMES[$count]}

#Now change hostname in postfix
postconf -ev myhostname=${HOST_NAMES[$count]}


count=$count+1
if [[ $count -gt 5 ]]
then
    count=0
fi


echo $count > counter.txt

When I run the script from command line, it's perfectly working and I can send email from a new IP and hostname pair. Now I want to execute this script before or after sending every outgoing email from our POSTFIX server. But I don't know how to trigger this script within POSTFIX.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.