Download files and transcoding then mailing them ALL automatically

simon said 懒是第一生产力

#! /bin/bash

YESTERDAY=`date +%Y%m%d -d 'yesterday'`
LF=/path/to/filename.log

download ()
{
	echo 'Downloading files...' | tee -a $LF
	curl "http://www.download.com/name.file"
}

makedirs()
{
	echo "Making dirs utf8.$YESTERDAY GBK.$YESTERDAY" | tee -a $LF
	if [ ! -x "Statement/utf8/$YESTERDAY"]; then
		mkdir -p "Statement/utf8/$YESTERDAY"
	fi

	if [ ! -x "Statement/zip/"]; then
		mkdir -p "Statement/zip/"
	fi

	if [ ! -x "Statement/GBK/$YESTERDAY"]; then
		mkdir -p "Statement/GBK/$YESTERDAY"
	fi
}

unzipFiles()
{
	echo "Finding *.zip then unzip them"| tee -a $LF
	find download -name "*.zip" -exec unzip -o -d Statement/GBK/$YESTERDAY {} \;
	find download -name "*.zip" -exec rm -f {} \;
}

transaferFiles()
{
	echo "Finding *.csv" | tee -a $LF
	files=`find Statement/GBK/$YESTERDAY -name "*.csv"`
	echo "iconf GBK to UTF8" | tee -a $LF
	for file in $files
	do
  		filename=`basename $file`
  		iconv -f GBK -t UTF-8 -c $file > Statement/utf8/$YESTERDAY/$filename
	done
}

zipFiles()
{
	echo "Zipping files into $YESTERDAY.Statement.zip" | tee -a $LF
	zip Statement/zip/$YESTERDAY.Statement.zip Statement/utf8/$YESTERDAY/*
}

sendingFiles()
{
	echo "Sending .zip to 2406204350@qq.com and simon" | tee -a $LF
	echo "mail title" -a Statement/zip/$YESTERDAY.Statement.zip -c address@mail.com
}
errorReport(){
	echo "对账单发送错误了快查看" |mail -s "ERROR:Statements sending error" address@mail.com
}
main()
{
	echo 'Start...'`date +%Y%m%d-%H:%M:%S` | tee -a $LF
	download
	makedirs
	unzipFiles
	transaferFiles
	zipFiles
	if [ ! -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		errorReport
	else
		sendingFiles
	fi
	echo 'Down...'`date +%Y%m%d-%H:%M:%S` >> $LF
	echo '-------------------------------' >> $LF
}

main

EOF