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