Shell se da cuenta de la instalación con un solo clic vsftpd + espera interacción automática

Implementación del script de shell:
1: Instale automáticamente el servicio vsftpd
2: Permita que los usuarios anónimos carguen archivos
3: Use esperar para realizar una interacción automática con los usuarios de ftp que cargan archivos.

#!/bin/bash
install_ftp(){
    
    
	count=$(rpm -qa |grep ftp|wc -l)
	if [ $count -ge 2 ]; then
		echo "vsftpd 已经安装了..."
	else
		yum -y install vsftpd ftp
	fi
}
edit_conf(){
    
    
	grep -w "#anon_upload_enable=YES" /etc/vsftpd/vsftpd.conf
	if [ $? -eq 0 ]; then
		sed -i '29 c anon_upload_enable=YES' /etc/vsftpd/vsftpd.conf
	fi

	grep -w "#anon_mkdir_write_enable=YES" /etc/vsftpd/vsftpd.conf
	if [ $? -eq 0 ]; then
		sed -i '33 c anon_mkdir_write_enable=YES' /etc/vsftpd/vsftpd.conf
	fi

	grep -w "no_anon_password=YES" /etc/vsftpd/vsftpd.conf
	if [ $? -ne 0 ]; then
		sed -i '128i no_anon_password=YES' /etc/vsftpd/vsftpd.conf
	fi

	grep -w "ftp_username=ftp" /etc/vsftpd/vsftpd.conf
	if [ $? -ne 0 ]; then
		sed -i '128i ftp_username=ftp' /etc/vsftpd/vsftpd.conf
	fi
}
restart_svc(){
    
    
	systemctl restart vsftpd
}
check_ftp(){
    
    
	netstat  -lptnu|grep 21
	if [ $? -eq 0 ]; then
		echo "vftpd 服务正在运行"
	else
		echo "启动服务.."
		systemctl start vsftpd
	fi
}
#echo "start running!"==============================================
date=$(date "+%Y-%m-%d")
cd /etc
tar zcvf etc.$date.tar.gz passwd shadow
#函数调用
install_ftp
edit_conf
restart_svc
check__ftp

if [ ! -d /var/ftp/pub/1806 ]; then
	mkdir -p /var/ftp/pub/1806
	chmod 777 /var/ftp/pub/1806 -R
fi

/usr/bin/expect <<eof
spawn ftp localhost
expect "Name*" 
send "ftp\n"
expect "ftp>*"
send "cd pub/1806\n"
expect "ftp>*"
send "put /etc/etc.$date.tar.gz etc.$date.tar.gz\n"
expect {
	"150 Ok to send data" { send_user "upload sucessfull!";send "quit\n" }
        "553*" { send_user "upload error!";send "quit\n" }

}

expect eof
eof

Supongo que te gusta

Origin blog.csdn.net/zhangshaohuas/article/details/109358966
Recomendado
Clasificación