#!/bin/sh
#删除7天前的新闻数据
. mp3_alias
if [ $# -eq 0 ];then
stat_date=`date -d"7 day ago" +'%F'`
else
stat_date=`date -d"$1" +'%F'`
fi
log_date=`date -d"$stat_date" +'%F'`
echo log_date=$log_date
file_date="newsinfo"
echo "select newsid,updatetime from music_news_info where updatetime < '$log_date'" |mp3db -s > $file_date
cat $file_date|awk '
{
printf("delete from music_news_content_%s where newsid=%s;\n",substr($1,length($1)),$1)
printf("delete from music_news_info where newsid = %s;\n",$1)
printf("dalete from music_news_images where newsid = %s;\n",$1)
}' > $file_sql
cat $file_sql|mp3db -f
log_date2=`date -d"$log_date" +"%Y%m%d"`
echo log_date2=$log_date2
#图片清理
dir_img="/www/scripts/music/zsc/news/img/"
cd $dir_img
ls -d * |awk '{gsub(/-/,"");print}'|sort -k1n |awk -v dp="$log_date2" '{if($1<dp){printf("rm -rf "substr($1,1,4)"-"substr($1,5,2)"-"substr($1,7)"\n")}}' | /bin/sh
#日志清理
dir_log="/www/scripts/music/zsc/news/log/"
cd $dir_log
echo "log"
ls | awk '{gsub(/-/,"");print}'|sort -k1n | awk -v dp="$log_date2" '{if($1<dp){printf("rm -rf "substr($1,1,4)"-"substr($1,5,2)"_"substr($1,7)"\n")}}' | /bin/sh
#删除7天前的新闻数据
. mp3_alias
if [ $# -eq 0 ];then
stat_date=`date -d"7 day ago" +'%F'`
else
stat_date=`date -d"$1" +'%F'`
fi
log_date=`date -d"$stat_date" +'%F'`
echo log_date=$log_date
file_date="newsinfo"
echo "select newsid,updatetime from music_news_info where updatetime < '$log_date'" |mp3db -s > $file_date
cat $file_date|awk '
{
printf("delete from music_news_content_%s where newsid=%s;\n",substr($1,length($1)),$1)
printf("delete from music_news_info where newsid = %s;\n",$1)
printf("dalete from music_news_images where newsid = %s;\n",$1)
}' > $file_sql
cat $file_sql|mp3db -f
log_date2=`date -d"$log_date" +"%Y%m%d"`
echo log_date2=$log_date2
#图片清理
dir_img="/www/scripts/music/zsc/news/img/"
cd $dir_img
ls -d * |awk '{gsub(/-/,"");print}'|sort -k1n |awk -v dp="$log_date2" '{if($1<dp){printf("rm -rf "substr($1,1,4)"-"substr($1,5,2)"-"substr($1,7)"\n")}}' | /bin/sh
#日志清理
dir_log="/www/scripts/music/zsc/news/log/"
cd $dir_log
echo "log"
ls | awk '{gsub(/-/,"");print}'|sort -k1n | awk -v dp="$log_date2" '{if($1<dp){printf("rm -rf "substr($1,1,4)"-"substr($1,5,2)"_"substr($1,7)"\n")}}' | /bin/sh