#!/bin/bash PASSWD="" echo ${PASSWD} MKDIR (){ for DIR in txt do if [ ! -d ./${DIR} ];then mkdir -p ${DIR} fi done } GET_NUM_TXT (){ DAT=`date +%F|awk -F- '{print $1$2}'` mysql -uroot -p${PASSWD} -e "use note;select pre_content from app_doc_doc;"|grep -Eo "note/media/[0-9]{6}/.{1,40}.[jpne]{2,3}g" >./txt/used.txt qshell listbucket imbed|awk '{print $1}'|grep "note" >./txt/qn.txt find ./media/2* -type f |sed 's#\.\/media\/#note\/media\/#g' >./txt/local.txt rm -rf ./txt/del_qn.txt for i in `cat ./txt/qn.txt` do grep ${i} ./txt/used.txt >>/dev/null 2>&1 if [ $? -ne 0 ];then echo ${i} >>./txt/del_qn.txt fi done rm -rf ./txt/del_local.txt for j in `cat ./txt/local.txt` do grep ${j} ./txt/used.txt >>/dev/null 2>&1 if [ $? -ne 0 ];then echo ${j} >>./txt/del_local.txt fi done JDUGE=`mysql -uroot -p${PASSWD} -e "use note;select count(*) from app_doc_doc where pre_content like '%${DAT}//%';"|awk 'NR==2 {print $1}'` if [ ${JDUGE} -ne 0 ];then echo "有\"//\"存在" else echo "所有连接正常" fi QN=`cat ./txt/qn.txt|wc -l` USED=`cat ./txt/used.txt|wc -l` if [ -f ./txt/del_qn.txt ];then DEL=`cat ./txt/del_qn.txt|wc -l` else DEL="0" fi LOCAL=`cat ./txt/local.txt|wc -l` echo "本地总数 ${LOCAL}" echo "七牛总数 ${QN}" echo "文章使用 ${USED}" } UPLOAD (){ #rm -rf /root/.qshell #qshell account UZrc4mwvcTQrJUo_XfRONEQtAucbS_BasqWZ1spa rxmxXEZTThYT_UliBp6htJe_NdvIcG63lDDn5n9W 王志珏 qshell qupload upload.conf } DEL_QN (){ qshell batchdelete imbed -i ./txt/del_qn.txt } DEL_LOCAL (){ for i in `cat ./txt/del_local.txt|sed 's#note\/##g'` do rm -rf ${i} done } CHANGE (){ #更换本地图片链接头为七牛云图片连接头 mysql -uroot -p123456 -e "use note;update app_doc_image set file_path=REPLACE(file_path,'/media/','http://cdn.imbed.liuyan.wang/note/media/') where file_path like '/media/%';" #设置图片来源为七牛云 mysql -uroot -p123456 -e "use note;update app_doc_image set remark='七牛云' where file_path like 'http://cdn.imbed.liuyan.wang/note/media/%'" mysql -uroot -p123456 -e "use note;update app_doc_doc set content=REPLACE(content,'src=\"/media/','src=\"http://cdn.imbed.liuyan.wang/note/media/') where content like '%src=\"/media/%';" #更换文章内图片链接 mysql -uroot -p123456 -e "use note;update app_doc_doc set pre_content=REPLACE(pre_content,'(/media/','(http://cdn.imbed.liuyan.wang/note/media/') where pre_content like '%(/media/%';" mysql -uroot -p123456 -e "use note;update app_doc_doc set pre_content=replace(pre_content,'${DAT}//','${DAT}/') where pre_content like '%${DAT}//%';" mysql -uroot -p123456 -e "use note;update app_doc_doc set content=replace(content,'${DAT}//','${DAT}/') where content like '%${DAT}//%';" mysql -uroot -p123456 -e "use note;update app_doc_image set file_path=replace(file_path,'${DAT}//','${DAT}/') where file_path like '%${DAT}//%';" } MKDIR GET_NUM_TXT cat <