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