主頁 > 知識庫 > 利用shell刪除數(shù)據(jù)表中指定信息和字段對應(yīng)的文件

利用shell刪除數(shù)據(jù)表中指定信息和字段對應(yīng)的文件

熱門標簽:地方門戶網(wǎng)站 鐵路電話系統(tǒng) 呼叫中心市場需求 Linux服務(wù)器 服務(wù)外包 百度競價排名 網(wǎng)站排名優(yōu)化 AI電銷

利用mysql shell命令讀取數(shù)據(jù)庫信息,刪除指定字段,以及字段對應(yīng)的文件,適用Linux平臺。

前面變量定義為數(shù)據(jù)基本配置

復(fù)制代碼 代碼如下:

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

您可能感興趣的文章:
  • shell備份文件、重命名文件、刪除指定文件的3個腳本分享
  • shell中刪除文件中重復(fù)行的方法
  • Shell中刪除某些文件外所有文件的3個方法

標簽:衡水 湘潭 崇左 仙桃 湖南 黃山 蘭州 銅川

巨人網(wǎng)絡(luò)通訊聲明:本文標題《利用shell刪除數(shù)據(jù)表中指定信息和字段對應(yīng)的文件》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266