postfix一键部署

#!/bin/bash
#author:dcc
#date:2018/05/26
#version:v1
#description:install postfix
if [ ! -d "$HOME/mylog" ];then
	mkdir $HOME/mylog
fi
config_file="/etc/postfix/main.cf"
log_path="$HOME/mylog/install.log"

#check postfix whether install
rpm -q postfix >/dev/null
if [ ! $? -eq 0 ];then
#test yum whether can use?

	test01=`yum repolist | grep 'repolist: '|sed -n 's/repolist: //p'`
	if [ "$test01" == "0" ];then
		echo "error_code:1;the yum.repo can't be used" >> $log_path
		echo "Error:yum can not be used"
		exit 1
	fi
	yum -y install postfix > /dev/null && echo "`date`:install postfix success" >> $log_path || echo "`date`:install postfix failed" && exit 1
fi

#config postfix
sed -in '/^mydestination =/s/=.*/=/' $config_file
sed -rin '/^#myori.*hostname$/c\
myorigin = dcc.cn' $config_file

#restart and enable postfix
systemctl restart postfix && echo "`date`:restart postfix success" >> $log_path || echo "`date`:restart postfix failed,you can use journalctl -xe to check" >> $log_path && exit 2

systemctl enable postfix && echo "`date`:enable postfix success" >> $log_path || echo "`date`:enable postfix failed" >> $log_path && exit 3

  不接受任何邮件,只用于发报警邮件

猜你喜欢

转载自www.cnblogs.com/dccrussell/p/9095827.html