Add SPF Records to all Domains

touch spf.sh

vim spf.sh

select and copy the following code (ctrl+A)

#!/usr/bin/python
import commands,os,time
curdate = time.strftime("%Y%m%d")
# Just in case things blow up
os.system("cp -Rp /var/named /var/named.backup")
os.chdir("/var/named")
files = commands.getoutput("ls *.db").split("\n")
for file in files:
domain = file.rstrip('db')
record = "\n%s IN TXT \"v=spf1 a mx ~all\"" %domain
f = open(file, 'a')
f.write(record)
f.close()
# Now we need to update the serial numbers
for file in files:
cmd = "sed -i -e \"s/[0-9]\{10\}/%s/\" %s" %(curdate, file)
os.system(cmd)
os.system("service named restart")
print "Done!"

hit insert on the keyboard

click inside the open file and paste above code then save the file.

:wq

modify it to run as an executable file

chmod 755 spf.sh

then run it…

./spf.sh

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.