利用shell刪除數(shù)據(jù)表中指定信息和字段對(duì)應(yīng)的文件
利用mysql shell命令讀取數(shù)據(jù)庫信息,刪除指定字段,以及字段對(duì)應(yīng)的文件,適用Linux平臺(tái)。
前面變量定義為數(shù)據(jù)基本配置
#!/bin/bash
#Program
# delete the database'info whick state is 3
#History:
# 2014/2/23 cjp First release
# 2014/3/5/ cjp change value'setting on 117
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/usr/local/bin:/usr/local/sbin:~/bin
export PATH
host="127.0.0.1"
port="3306"
user="user"
passwd="passwd"
dbname="database"
tablename="table"
field="t_field"
outField="t_id,t_path"
fileRootPath="/var/www/html/apath"
filePath=""
#checkdown data
mysql -h$host -P$port -u$user -p$passwd $dbname -e "SET NAMES utf8;SELECT ${outField} FROM ${tablename} WHERE ${field} = 3" > data_info
date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %z" >> del_log.log
#delete image file and mysql data
sed '1d' data_info | while read line
do
echo $line > findtemp
awk '{print $2}' findtemp > imagetemp
cat imagetemp | while read imagedata
do
filePath=${fileRootPath}${imagedata}
echo $filePath >> del_log.log
rm -f $filePath
done
awk '{print $1}' findtemp > idtemp
cat idtemp | while read iddata
do
mysql -h$host -P$port -u$user -p$passwd $dbname -e "SET NAMES utf8;DELETE FROM ${tablename} WHERE s_id = ${iddata}"
done
done
rm -f data_info
rm -f imagetemp
rm -f idtemp
echo "^-^ clean!"
相關(guān)文章
shell腳本實(shí)現(xiàn)監(jiān)控shell腳本的執(zhí)行流程及變量的值
這篇文章主要介紹了shell腳本實(shí)現(xiàn)監(jiān)控shell腳本的執(zhí)行流程及變量的值本文使用shell完成對(duì)執(zhí)行過程中條件語句中的變量的變化的監(jiān)控和整個(gè)程序的執(zhí)行流程的觀察功能,需要的朋友可以參考下2015-03-03
實(shí)現(xiàn)android自動(dòng)化測(cè)試部署與運(yùn)行Shell腳本分享
這篇文章主要介紹了實(shí)現(xiàn)android自動(dòng)化測(cè)試部署與運(yùn)行Shell腳本分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03
淺析Shell腳本中的條件判斷[?]與[[?]]的區(qū)別
在編寫?Shell?腳本時(shí),條件判斷是控制腳本流程的重要手段,Shell?提供了多種方式來進(jìn)行條件判斷,其中[?]和[[?]]是兩種常見的條件測(cè)試表達(dá)式,下面我們就來看看兩者的區(qū)別吧2024-12-12
java應(yīng)用啟動(dòng)與停止的shell腳本分享
這篇文章主要和大家分享三個(gè)shell腳本,分別是jvm啟動(dòng)參數(shù)相關(guān)的setjvment.sh,利用java命令啟動(dòng)進(jìn)程的start.sh和停止java進(jìn)程的stop.sh,有需要的可以參考下2023-10-10
shell周期差量備份文件夾的實(shí)現(xiàn)代碼
這篇文章主要介紹了shell周期差量備份文件夾的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
linux定時(shí)任務(wù)基礎(chǔ)命令介紹(14)
這篇文章主要為大家詳細(xì)介紹了linux定時(shí)任務(wù)基礎(chǔ)命令,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
Shell腳本實(shí)現(xiàn)關(guān)閉多余的tty終端
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)關(guān)閉多余的tty終端,本文腳本適用centos6系統(tǒng),請(qǐng)根據(jù)自己的服務(wù)器系統(tǒng)情況選擇使用,需要的朋友可以參考下2014-12-12
linux 隨機(jī)密碼生成工具mkpasswd詳解及實(shí)例
這篇文章主要介紹了linux 隨機(jī)密碼生成工具mkpasswd詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-04-04

