FTP服务器管理【Linux运维之道之脚本案例】
今天看到51CTO正在搞Linux Shell 腳本大賽,特地將自己的處女作發(fā)出來(lái),希望能夠得到分享。
這里說(shuō)一下這個(gè)腳本的功能,這個(gè)腳本主要用來(lái)實(shí)現(xiàn)VSFTPD服務(wù)器的基礎(chǔ)管理,主要用于方便運(yùn)維管理。代碼不是很美,還請(qǐng)各位多多指教。
這個(gè)代碼主要基于本地用戶(hù)管理、有需求基于LDAP認(rèn)證管理的朋友,可以聯(lián)系我,LDAP認(rèn)證的功能上將更強(qiáng)大了些。
管理界面:
代碼部份:
read -p "請(qǐng)選擇您要做的操作:" caozuo ?
case $caozuo in ? ?
? ?0) read -p "請(qǐng)輸入您要修改密碼的用戶(hù)名: " selectuser ? ?
? ? ? ?while [ ! "$selectuser" ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $selectuser` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您輸入的用戶(hù)名$selectuser不存在,請(qǐng)重新輸入要查詢(xún)的用戶(hù)名,退出請(qǐng)按q鍵: " selectuser ? ?
? ? ? ?if [ "$selectuser" ] && [ "$selectuser" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?passwd $selectuser ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1修改用戶(hù)$selectuser密碼" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "您已經(jīng)成功修改用戶(hù)$selectuser的密碼,按回車(chē)鍵繼續(xù)操作" var ? ?
;; ? ?
? ?1) read -p "請(qǐng)輸入您要查詢(xún)的用戶(hù)名: " selectuser ? ?
? ? ? ?while [ ! "$selectuser" ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $selectuser` ] ? ?
? ? ? ?do ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)用戶(hù)$selectuser" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "對(duì)不起,查詢(xún)的用戶(hù)名$selectuser不存在,請(qǐng)重新輸入要查詢(xún)的用戶(hù)名,退出請(qǐng)按q鍵: " selectuser ? ?
? ? ? ?if [ "$selectuser" ] && [ "$selectuser" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)用戶(hù)$selectuser" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "您查詢(xún)的用戶(hù)$selectuser為FTP用戶(hù),按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? ?2) read -p "請(qǐng)輸入您需要添加的用戶(hù)名: " adduser ? ?
? ? ? ?while [ ! "$adduser" ] || ( [ "$adduser" ] && [ `more /etc/vsftpd/chroot_list | grep -w $adduser` ] ) ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您的操作有誤,用戶(hù)名不能為空,或您添加的用戶(hù)已經(jīng)存在,請(qǐng)重新輸入要查詢(xún)的用戶(hù)名,退出請(qǐng)按q鍵: " adduser ? ?
? ? ? ?if [ "$adduser" ] && [ "$adduser" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?useradd $adduser -d /opt/vsftp/$adduser -s /sbin/nologin ? ?
? ? ? ?chmod -R 777 /opt/vsftp/$adduser ? ?
? ? ? ?echo $adduser@123 | passwd --stdin $adduser ? ?
? ? ? ?echo "$adduser" >> /etc/vsftpd/chroot_list ? ?
? ? ? ?setquota -u $adduser ?512000 614400 0 0 /opt ? ?
? ? ? ?cp /etc/vsftpd/vconf/moban /etc/vsftpd/vconf/$adduser
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1添加用戶(hù)$adduser" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ?
? ? ? ?read -p "您添加用戶(hù)$adduser成功,按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? 3) read -p "請(qǐng)輸入您需要?jiǎng)h除的用戶(hù)名: " deluser ? ?
? ? ? ?while [ ! "$deluser" ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $deluser` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您輸入的用戶(hù)名$deluser不存在,請(qǐng)重新輸入要?jiǎng)h除的用戶(hù)名,退出請(qǐng)按q鍵: " deluser ? ?
? ? ? ?if [ "$deluser" ] && [ "$deluser" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?userdel $deluser ? ?
? ? ? ?rm -rf /opt/vsftp/$deluser/.gnome2 ? ?
? ? ? ?rm -rf /opt/vsftp/$deluser/.bashrc ? ?
? ? ? ?rm -rf /opt/vsftp/$deluser/.bash_profile ? ?
? ? ? ?rm -rf /opt/vsftp/$deluser/.bash_logout ? ?
? ? ? ?rm -rf /etc/vsftpd/vconf/$deluser
? ? ? ?umount /opt/vsftp/$deluser ?
? ? ? ?mv /opt/vsftp/$deluser /opt/vsftp/bak$deluser ? ?
? ? ? ?rm -rf /opt/vsftp/$deluser ? ?
? ? ? ?sed -i "/$deluser/d" /etc/vsftpd/chroot_list ? ?
? ? ? ?sed -i "/$deluser/d" /etc/vsftpd/mountuser.sh ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1刪除用戶(hù)$deluser" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "您已經(jīng)成功刪除用戶(hù)$deluser,按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? 4) more /etc/vsftpd/chroot_list ? ?
? ? ? ?read -p "以上為所有FTP用戶(hù),按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? 5) read -p "請(qǐng)輸入您要查詢(xún)限額的用戶(hù)名: " selectquota ? ?
? ? ? ?while [ ! "$selectquota" ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $selectquota` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您輸入的用戶(hù)名$selectquota不存在,請(qǐng)重新輸入要查詢(xún)限額的用戶(hù)名,退出請(qǐng)按q鍵: " selectquota ? ?
? ? ? ?if [ "$selectquota" ] && [ $selectquota == q ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?quota $selectquota | sed -n '3p' | echo "當(dāng)前用戶(hù)的軟限制為: `awk '{print $3}'`KB" ? ?
? ? ? ?quota $selectquota | sed -n '3p' | echo "當(dāng)前用戶(hù)的硬限制為: `awk '{print $4}'`KB" ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)用戶(hù)$selectquota磁盤(pán)限額信息" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "當(dāng)前用戶(hù)的磁盤(pán)限額如上,按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? 6) read -p "請(qǐng)輸入您要修改限額的用戶(hù)名: " revisequota ? ?
? ? ? ?while [ ! "$revisequota" ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $revisequota` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您輸入的用戶(hù)名$revisequota不存在,請(qǐng)重新輸入要查詢(xún)限額的用戶(hù)名,退出請(qǐng)按q鍵: " revisequota ? ?
? ? ? ?if [ "$revisequota" ] && [ $revisequota == q ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?quota $revisequota | sed -n '3p' | echo "修改前用戶(hù)的軟限制為: `awk '{print $3}'`KB" ? ?
? ? ? ?quota $revisequota | sed -n '3p' | echo "修改前用戶(hù)的硬限制為: `awk '{print $4}'`KB" ? ?
? ? ? ?read -p "請(qǐng)修改您要修改的用戶(hù)軟限制值,默認(rèn)單位為KB: " quota1 ? ?
? ? ? ?while [ ! $quota1 ]; ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,修改用戶(hù)的軟限制值不能為空,請(qǐng)重新輸入軟限制值,退出請(qǐng)按q鍵: " quota1 ? ?
? ? ? ?if [ $quota1 ];then ? ?
? ? ? ?if [ $quota1 == q ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?read -p "請(qǐng)修改您要修改的用戶(hù)硬限制值,默認(rèn)單位為KB: " quota2 ? ?
? ? ? ?while [ ! $quota2 ] || [ $quota2 -lt $quota1 ]; ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,修改用戶(hù)的硬限制值不能為空,且硬限制的值不能小于軟限制的值,請(qǐng)重新輸入硬限制值,退出請(qǐng)按q鍵: " quota2 ? ?
? ? ? ?if [ "$quota2" ] && [ "$quota2" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?setquota -u $revisequota ?$quota1 $quota2 0 0 /opt ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1修改用戶(hù)$revisequota軟限制為: $quota1 硬限制為: $quota2" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?quota $revisequota | sed -n '3p' | echo "修改后用戶(hù)的軟限制為: `awk '{print $3}'`KB" ? ?
? ? ? ?quota $revisequota | sed -n '3p' | echo "修改后用戶(hù)的硬限制為: `awk '{print $4}'`KB" ? ?
? ? ? ?read -p "當(dāng)前用戶(hù)修改后磁盤(pán)限額如上,按回車(chē)鍵繼續(xù)" var ? ?
;; ? ?
? ? 7) read -p "請(qǐng)輸入您要查詢(xún)的用戶(hù)名: " selectuser ? ?
? ? ? ?while [ ! $selectuser ] || [ ! `more /etc/vsftpd/chroot_list | grep -w $selectuser` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您查詢(xún)的用戶(hù)名$selectuser不存在,請(qǐng)重新輸入,退出請(qǐng)按q鍵: " selectuser ? ?
? ? ? ?if [ "$selectuser" ] && [ "$selectuser" == "q" ];then ? ?
? ? ? ?exit ? ?
? ? ? ?fi ? ?
? ? ? ?done ? ?
? ? ? ?read -p "請(qǐng)輸入您要查詢(xún)的日期(格式:2013-07-11 08:32:21): " datetime3 ? ?
? ? ? ?while [ ! $datetime3 ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起您的輸入有誤,日期時(shí)間不能空,請(qǐng)重新輸入: " datetime3 ? ?
? ? ? ?done ? ?
? ? ? ?read -p "請(qǐng)輸入您要查詢(xún)的操作動(dòng)作(DELETE、MKDIR、UPLOAD、RMDIR、DOWNLOAD、LOGIN): " opreate ? ?
? ? ? ?while [ ! $opreate ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,操作動(dòng)作不能為空,請(qǐng)重新輸入: " opreate ? ?
? ? ? ?done ? ?
? ? ? ?while ( [ $opreate != 'MKDIR' ] && [ $opreate != 'UPLOAD' ] && [ $opreate != 'DELETE' ] && [ $opreate != 'LOGIN' ] && [ $opreate != 'RMDIR' ] && [ $o ? ?
preate != 'DOWNLOAD' ] ) ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起您輸入的操作動(dòng)作有誤,請(qǐng)重新輸入: " opreate ? ?
? ? ? ?done ? ?
? ? ? ?echo " 操作日期|操作時(shí)間|操作人|是否成功|操作動(dòng)作|IP地址|操作內(nèi)容" > /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?more /var/log/messages | grep $selectuser] | grep $opreate | grep $datetime3 | awk '{print $1"|"$2"|"$5"|"$6"|"$7"|"$9"|"$10 }' >> /opt/vsftp/ftplog/ ? ?
"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/://3' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/"//g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/\[//' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/]//' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/,//g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/UPLOAD/上傳資料/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/DELETE/刪除文件/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/LOGIN/用戶(hù)登錄/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/RMDIR/刪除目錄/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/MKDIR/新建目錄/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/DOWNLOAD/下載資料/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/OK/成功/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?sed -i 's/FAIL/失敗/g' /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)用戶(hù)$selectuser的操作動(dòng)作$opreate日志" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "直接查看請(qǐng)按a鍵,下載到Win查看請(qǐng)按b鍵: " abjian ? ?
? ? ? ?if [ "$abjian" == "a" ];then ? ?
? ? ? ?more /opt/vsftp/ftplog/"$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?read -p "以上為指定用戶(hù)的操作日志,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?elif [ "$abjian" == "b" ];then ? ?
? ? ? ?cd /opt/vsftp/ftplog ? ?
? ? ? ?sz "$timedate1""$selectuser""$opreate".xls ? ?
? ? ? ?read -p "指定用戶(hù)的操作日志已經(jīng)成功導(dǎo)出到Win,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?fi ? ?
;; ? ?
? ?8) read -p "請(qǐng)輸入您要查詢(xún)的日期(格式:2012-09-12): " riqi ? ?
? ? ? ?while [ ! $riqi ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起日期不能為空,請(qǐng)重新輸入(格式:2012-09-12): " riqi ? ?
? ? ? ?done ? ?
? ? ? ?while [ `echo $riqi | grep -q '^[1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' && echo ! aa || echo aa` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "您輸入的日期格式錯(cuò)誤,請(qǐng)重新輸入(格式:2012-09-12): " riqi ? ?
? ? ? ?done ? ?
? ? ? ?read -p "請(qǐng)輸入您要查詢(xún)的時(shí)間,(格式:23:12): " shijian ? ?
? ? ? ?if [ ! $shijian ];then ? ?
? ? ? ?echo " 操作日期|操作時(shí)間|操作人|是否成功|操作動(dòng)作|IP地址|操作內(nèi)容" > /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? more /var/log/messages | grep $riqi | grep vsftpd | awk '{print $1"|"$2"|"$5"|"$6"|"$7"|"$9"|"$10 }' >> /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/://3' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/"//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/\[//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/]//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/,//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/UPLOAD/上傳資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/DELETE/刪除文件/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/LOGIN/用戶(hù)登錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/RMDIR/刪除目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/MKDIR/新建目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/DOWNLOAD/下載資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/OK/成功/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?sed -i 's/FAIL/失敗/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)?nèi)掌跒?$riqi的所有用戶(hù)操作記錄" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "直接查看請(qǐng)按a鍵,下載到Win查看請(qǐng)按b鍵: " abjian ? ?
? ? ? ?if [ "$abjian" == "a" ];then ? ?
? ? ? ?more /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?read -p "以上為指定用戶(hù)的操作日志,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?elif [ "$abjian" == "b" ];then ? ?
? ? ? ?cd /opt/vsftp/ftplog ? ?
? ? ? ?sz "$timedate1"查詢(xún)"$riqi".xls ? ?
? ? ? ?read -p "指定用戶(hù)的操作日志已經(jīng)成功導(dǎo)出到Win,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?fi ? ?
? ? ? ?else ? ?
? ? ? ?while [ `echo $shijian | grep -q '^[0-9][0-9]:[0-9][0-9]$' && echo ! aa || echo aa` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "您輸入的時(shí)間格式不正確,請(qǐng)重新輸入(格式:23:12): " shijian ? ?
? ? ? ?done ? ?
? ? ? ?shi=`echo ${shijian:0:2}` ? ?
? ? ? ?jian=`echo ${shijian:${#shijian}-2:${#shijian}}` ? ?
? ? ? ?echo "操作日期|操作時(shí)間|操作人|是否成功|操作動(dòng)作|IP地址|操作內(nèi)容" > /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?more /var/log/messages | grep $riqi | grep $shijian | grep vsftpd | awk '{print $1"|"$2"|"$5"|"$6"|"$7"|"$9"|" $10 }' >> /opt/vsftp/ftplog/"$timedate ? ?
1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/://3' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/"//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/\[//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/]//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/,//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/UPLOAD/上傳資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/DELETE/刪除文件/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/LOGIN/用戶(hù)登錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/RMDIR/刪除目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/MKDIR/新建目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/DOWNLOAD/下載資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/OK/成功/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?sed -i 's/FAIL/失敗/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian" ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)?nèi)掌跒?$riqi時(shí)間為:$shijian的所有用戶(hù)操作記錄" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "直接查看請(qǐng)按a鍵,下載到Win查看請(qǐng)按b鍵: " abjian ? ?
? ? ? ?if [ "$abjian" == "a" ];then ? ?
? ? ? ?more /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$riqi"-"$shi"."$jian".xls ? ?
? ? ? ?read -p "以上為指定用戶(hù)的操作日志,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?elif [ "$abjian" == "b" ];then ? ?
? ? ? ?cd /opt/vsftp/ftplog ? ?
? ? ? ?sz "$timedate1"查詢(xún)"$riqi"-"$shi"."$jian".xls ? ?
? ? ? ?read -p "指定用戶(hù)的操作日志已經(jīng)成功導(dǎo)出到Win,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?fi ? ?
? ? ? ?fi ? ?
;; ? ?
? ? 9) read -p "請(qǐng)輸入您要查詢(xún)的用戶(hù)名: " selectuser ? ?
? ? ? ?while [ ! $selectuser ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,查詢(xún)的用戶(hù)名不能為空,請(qǐng)重新輸入要查詢(xún)的用戶(hù)名: " selectuser ? ?
? ? ? ?done ? ?
? ? ? ?while [ ! `more /etc/vsftpd/chroot_list | grep -o $selectuser` ] ? ?
? ? ? ?do ? ?
? ? ? ?read -p "對(duì)不起,您查詢(xún)的用戶(hù)名不存在,請(qǐng)重新輸入要查詢(xún)的用戶(hù)名: " selectuser ? ?
? ? ? ?done ? ?
? ? ? ?echo "操作日期|操作時(shí)間|操作人|是否成功|操作動(dòng)作|IP地址|操作內(nèi)容" > /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?more /var/log/messages | grep $selectuser | grep vsftpd | awk '{print $1 "|" $2 "|" $5 "|" $6 "|"$7 "|" $9 "|" $10 }' >> /opt/vsftp/ftplog/"$timedate ? ?
1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/://3' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/"//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/\[//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/]//' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/,//g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/UPLOAD/上傳資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/DELETE/刪除文件/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/LOGIN/用戶(hù)登錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/RMDIR/刪除目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/MKDIR/新建目錄/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/DOWNLOAD/下載資料/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/OK/成功/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?sed -i 's/FAIL/失敗/g' /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查詢(xún)?nèi)掌跒?$selectuser的所有用戶(hù)操作記錄" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "直接查看請(qǐng)按a鍵,下載到Win查看請(qǐng)按b鍵: " abjian ? ?
? ? ? ?if [ "$abjian" == "a" ];then ? ?
? ? ? ?more /opt/vsftp/ftplog/"$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?read -p "以上為指定用戶(hù)的操作日志,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?elif [ "$abjian" == "b" ];then ? ?
? ? ? ?cd /opt/vsftp/ftplog ? ?
? ? ? ?sz "$timedate1"查詢(xún)"$selectuser".xls ? ?
? ? ? ?read -p "指定用戶(hù)的操作日志已經(jīng)成功導(dǎo)出到Win,按回車(chē)鍵繼續(xù)操作" var ? ?
? ? ? ?fi ? ?
;; ? ?
? ?10) ls /opt/vsftp/ftplog/ | more ? ?
? ? ? ?echo "記錄: 管理員$adminroot于$timedate1查看了所有導(dǎo)出的用戶(hù)操作日志文件名" >> /opt/vsftp/adminlog/"$adminroot""$timedate2" ? ?
? ? ? ?read -p "以上為所有已導(dǎo)出用戶(hù)操作日志文件名,按回車(chē)鍵繼續(xù)" var ? ?
;;
說(shuō)明:
由于代碼篇幅太大,這里貼出前10項(xiàng)功能代碼,希望能夠給有需求的朋友能起到一個(gè)拋磚引玉的作用。
總結(jié)
以上是生活随笔為你收集整理的FTP服务器管理【Linux运维之道之脚本案例】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Codeforces Round #71
- 下一篇: 京东精英接班后,永辉能否借“科技”重回千