#!/bin/bash config_path=/work/ftp/vsftpd_config cd /work/ftp cat screen.txt read -p "请选择您要做的操作:" caozuo case $caozuo in 0) read -p "请输入共享文件夹名字:" ftpdocument read -p "请输入原来的账号:" ftpuser read -p "请输入新的账号:" ftpusernew read -p "请输入新的密码:" ftppasswdnew cd /work/ftp if [ -d $ftpdocument ] then cd ${config_path}/vuser_conf modifile=`grep -rn $ftpdocument ./$ftpuser` if [ ! -f $ftpusernew ] || [ "$ftpusernew"x = "$ftpuser"x ] then if [ -f $ftpuser ] && [ -n "$modifile" ] then mv $ftpuser $ftpusernew >/dev/null 2>&1 cd ${config_path} num=`cat -n vuser_passwd.txt | grep $ftpuser | awk ‘{print $1}‘ | awk ‘NR==1{print}‘` num=$(( $num + 1 )) sed -i ‘s/‘"$ftpuser"‘/‘"$ftpusernew"‘/g‘ vuser_passwd.txt sed -i ‘‘"${num}s"‘/.*/‘"$ftppasswdnew"‘/g‘ vuser_passwd.txt db_load -T -t hash -f /work/ftp/vsftpd_config/vuser_passwd.txt /work/ftp/vsftpd_config/vuser_passwd.db echo "`date` administrator change the username $ftpuser with newuser $ftpusernew and new password $ftppasswdnew" >> ${config_path}/adminedit.log else echo "共享文件夹初始账号输入错误" fi else echo "账号已经存在了,请重新输入新账号" fi else echo "该共享文件夹不存在" fi ;; 1) read -p "请输入你想要共享的文件夹名字:" ftpdocument read -p "请输入账号:" ftpuser read -p "请输入密码:" ftppasswd cd /work/ftp if [ ! -d $ftpdocument ] then mkdir $ftpdocument cd /work/ftp/vsftpd_config/vuser_conf if [ ! -f $ftpuser ] then echo $ftpuser>>/work/ftp/vsftpd_config/vuser_passwd.txt echo $ftppasswd>>/work/ftp/vsftpd_config/vuser_passwd.txt db_load -T -t hash -f /work/ftp/vsftpd_config/vuser_passwd.txt /work/ftp/vsftpd_config/vuser_passwd.db cd /work/ftp/vsftpd_config/vuser_conf sudo touch $ftpuser echo "local_root=/work/ftp/$ftpdocument write_enable=YES anon_umask=022 anon_world_readable_only=NO anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES">>$ftpuser echo "`date` administrator build new focument $ftpdocument with user $ftpuser" >> ${config_path}/adminedit.log else cd /work/ftp rm -rf $ftpdocument echo "该用户名已经存在,请重新输入" fi else echo "共享文件夹已经存在,请重新输入" fi ;; 2) read -p "请输入你要查询的用户名:" ftpuser cd ${config_path} num=`cat -n vuser_passwd.txt | grep $ftpuser | awk ‘{print $1}‘ | awk ‘NR==1{print}‘` num=$(( $num + 1 )) cd /work/ftp/vsftpd_config/vuser_conf if [ -f $ftpuser ] then echo "该用户的密码" cd .. sed -n ‘‘${num}‘,1p‘ vuser_passwd.txt echo "该用户对应的共享文件夹" cd vuser_conf cat $ftpuser | awk ‘NR==1{print}‘ | awk -F "/" ‘{print $4}‘ else echo "该用户名不存在" fi ;; 3) read -p "请输入你要删除的用户(对应的共享文件夹也会被删除):" ftpuser cd ${config_path} num=`cat -n vuser_passwd.txt | grep $ftpuser | awk ‘{print $1}‘ | awk ‘NR==1{print}‘` cd vuser_conf if [ -f $ftpuser ] then filename=`cat $ftpuser | awk ‘NR==1{print}‘ | awk -F "/" ‘{print $4}‘` cd .. sed -i ‘‘${num}‘d‘ vuser_passwd.txt sed -i ‘‘${num}‘d‘ vuser_passwd.txt cd /work/ftp rm -rf $filename cd ${config_path}/vuser_conf rm -rf $ftpuser echo "`date` administrator delete the user $ftpuser" >> ${config_path}/adminedit.log else echo "该用户名不存在" fi ;; 4) cd ${config_path}/vuser_conf ls -l ;; 5) cd /var/log cat vsftpd.log ;; 6) read -p "请输入你要查询日志的用户名:" ftpuser cd /var/log cat vsftpd.log | grep $ftpuser ;; 7) cat ${config_path}/adminedit.log ;; *) echo "请重新输入选择的操作" ;; esac
客户端脚本
#!/bin/bash read -p "please input the ftp user name:" ftpuser read -p "please input the user password:" ftppasswd read -p "please input the document name you want to get:" ftpdocument ftp -i -in << ! open 192.168.100.184 user $ftpuser $ftppasswd passive bin mget $ftpdocument bye !
时间: 2024-10-15 02:02:05