Use the shell to delete the files that correspond to the specified information and fields in the datasheet _linux shell

Source: Internet
Author: User

Use the MySQL shell command to read the database information, delete the specified fields, and the corresponding files of the field, the Linux platform.

The preceding variable is defined as the data base configuration

Copy Code code as follows:

#!/bin/bash
#Program
# Delete the database ' info whick State is 3
#History:
# 2014/2/23 CJP
# 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
Todo
echo $line > Findtemp
awk ' {print $} ' findtemp > Imagetemp
Cat Imagetemp | While Read ImageData
Todo
Filepath=${filerootpath}${imagedata}
echo $filePath >> Del_log.log
Rm-f $filePath
Done

awk ' {print $} ' findtemp > Idtemp
Cat Idtemp | While Read Iddata
Todo
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!"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.