`
chnic
  • 浏览: 225826 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

shell script II

阅读更多
#!/bin/sh

HOME=xxx
CONFIGFILE=HouseKeeping.config
LOGFILE=HouseKeepingLog.txt
date | tee -a $LOGFILE | cat
echo "**********************Script start**********************" | tee -a $LOGFILE | cat
cd $HOME

count=0
sum=0

while read conLine  
do
	count=`expr $count + 1`
	path=`echo $conLine | awk '{print $1}'`   
	type=`echo $conLine | awk '{print $2}'`
	time=`echo $conLine | awk '{print $3}'`
	
	echo "No."$count" Directory: "$path | tee -a $LOGFILE | cat

	if [ -e $path ]; then
		if [ $type -eq 1 ]; then
			find $path ! -path $path -type d -mtime +$time | while read LINE
			do
				sum=`expr $sum + 1`
				echo "Remove Directory "$LINE | tee -a $LOGFILE | cat 
				rm -rf "$LINE"
			done
		elif [ $type -eq 2 ]; then
			find $path -type f -mtime +$time | while read LINE
			do
				sum=`expr $sum + 1`
				echo "Remove File "$LINE | tee -a $LOGFILE | cat
				rm -rf "$LINE"
			done
		else
			echo "Illegal Parameter." | tee -a $LOGFILE | cat
		fi
	else
		echo "The specified directory doesn't exist." | tee -a $LOGFILE | cat
	fi
done < $CONFIGFILE  

echo $count" directory have been processed and "$sum" File/Folder have been deleted." | tee -a $LOGFILE | cat
echo "**********************Script end**********************" | tee -a $LOGFILE | cat
date | tee -a $LOGFILE | cat
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics