#!/bin/bash# Author : standby@gmail.com# Date : 2018-02-27NGX_CONF="/usr/local/nginx/conf/nginx.conf"# Get the dev which contains ./liveroot/ function get_point(){ arr=(`df -HT |grep -v 'Filesystem' |grep -E '[0-9]{1,2}T' |awk '{print $NF}'`) for dev in ${arr[*]} do [ -d $dev"/liveroot/live" ] && point=$dev && break done echo $point}# Start here...point=$(grep '/liveroot;' $NGX_CONF |awk -F / '{print "/"$2}')if [ ! -z "$point" ]then res=$(echo $point |grep -v ' ' |wc -l) [ $res -eq 0 ] && point=`get_point`else point=`get_point`fi# [live] Touch the stream-name.data file to avoiding deleted.for i in $(find $point/liveroot/live -type d ! -name "*mon" |awk -F / '{print $5}')do [ -f $point"/liveroot/live/"$i"/"$i".data" ] && touch $point/liveroot/live/$i/$i.datadone# [tslive] Touch the stream-name.data file to avoiding deleted.for i in $(find $point/liveroot/tslive -type d ! -name "*mon" |awk -F / '{print $5}')do [ -f $point"/liveroot/tslive/"$i"/"$i".data" ] && touch $point/liveroot/tslive/$i/$i.datadone# Clean the old files which contains [*.data | *.pht | *.ts | core.* | temp_* | *.m3u8 | *.log] and keep 3 days only.find $point/liveroot/live -ctime +2 -type f -name "*.data" -exec /bin/rm -f {} \;find $point/liveroot/live -ctime +2 -type f -name "*.pht" -exec /bin/rm -f {} \;find $point/liveroot/live -ctime +2 -type f -name "*.m3u8" -exec /bin/rm -f {} \;find $point/liveroot/live -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} \;find $point/liveroot/live -ctime +2 -type f -name "core.*" -exec /bin/rm -f {} \;find $point/liveroot/live -ctime +2 -type f -name "temp_*" -exec /bin/rm -f {} \;#find $point/liveroot/tslive -ctime +2 -type f -name "*.ts" -exec /bin/rm -f {} \;find $point/liveroot/tslive -path $point"/liveroot/tslive/c1_mon" -prune -o -ctime +2 -type f -name "*.ts" -exec /bin/rm -f {} \;find $point/liveroot/tslive -ctime +2 -type f -name "*.pht" -exec /bin/rm -f {} \;find $point/liveroot/tslive -ctime +2 -type f -name "*.m3u8" -exec /bin/rm -f {} \;find $point/liveroot/tslive -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} \;find $point/liveroot/tslive -ctime +2 -type f -name "core.*" -exec /bin/rm -f {} \;find $point/liveroot/tslive -ctime +2 -type f -name "temp_*" -exec /bin/rm -f {} \;# Clean the ffmpeg log and keep 3 days only.find $point/liveroot/livelog -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} \;# [live] Clean the old ./liveroot/live/some_sub_dirs which cleated 5 days ago and has less 5 files contained.for i in $(find $point/liveroot/live -ctime +4 -type d ! -name "*_mon")do [ $i == $point"/liveroot/live" ] && continue #ls -ld --time-style=long-iso $i |awk '{print $6" "$7}' num=$(ls -l $i |grep '^-' |wc -l) [ $num -lt 5 ] && rm -rf $idone# [tslive] Clean the old ./liveroot/tslive/some_sub_dirs which cleated 5 days ago and has less 5 files contained.for i in $(find $point/liveroot/tslive -ctime +4 -type d ! -name "*_mon")do [ $i == $point"/liveroot/tslive" ] && continue num=$(ls -l $i |grep '^-' |wc -l) [ $num -lt 5 ] && rm -rf $idone