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