1. 程式人生 > >自動部署ftp腳本

自動部署ftp腳本

test echo sftp con lse lis ash running ins

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

#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

#install
echo "`date`:install ftp start:" >> $log_path
yum -y install vsftpd >> $log_path

#check
rpm -q vsftpd &> /dev/null
if [ $? -eq 0 ];then
	systemctl restart vsftpd &> /dev/null
	systemctl enable vsftpd &> /dev/null
else
	echo "vsftpd install failed" >> $log_path
	exit 2
fi
#check
systemctl status vsftpd | grep ‘running‘ &> /dev/null
if [ ! $? -eq 0 ];then
	echo "start vsftpd failed" >> $log_path
	exit 3
else
	echo "start vsftpd success" >> $log_path
fi

#firewall config
firewall-cmd --permanent --zone=trusted --add-service=ftp &> /dev/null
if [ $? -eq 0 ];then
	firewall-cmd --reload &> /dev/null
	if [ $? -eq 0 ];then
		echo success
		exit 0
	else 
		echo "firewall reload failed" >> $log_path
		exit 4
	fi
else
	echo "firewall set failed" >> $log_path
	exit 5	
fi

  

自動部署ftp腳本