#!/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 !