DOWNLOAD FILES AND TRANSCODING THEN MAILING THEM ALL AUTOMATICALLY

#! /bin/bash
#version 2.1
#auther simon@codewalker.me
LF=/var/log/statement/daily/statement.log

#current work directory
CW='/path/to/work/space'
YESTERDAY=`date +%Y%m%d -d 'yesterday'`
if [ $1 ]; then
	YESTERDAY=$1
fi

download ()
{
	if [ -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		echo "Already sending $YESTERDAY.statement" | tee -a $LF
		read -n1 -p "Do you want force to send mail [Y|N]? " current_input
		case $current_input in
		Y|y)
			echo "Downloading ${YESTERDAY}_zhye-yh-cqg.zip file" | tee -a $LF
			curl "http://www.someurl.com/files"
		;;
		N|n)
			echo 'Choice no. exit' | tee -a $LF
		;;
		esac
			
	else
		if [ ! -f "download/$YESTERDAY/$YESTERDAY"_zhye-yh-cqg.zip ];then
			echo "Downloading ${YESTERDAY}_zhye-yh-cqg.zip file" | tee -a $LF
			curl "http://www.someurl.com/files"
		else
			echo "Found ${YESTERDAY}_*.zip zips will not download..." | tee -a $LF
		fi
	fi
}

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

	if [ ! -x "Statement/zip/" ]; then  
		echo "Making dir zip" | tee -a $LF
		mkdir -p "Statement/zip/" 
	else
		echo 'dir Statement/zip/ existed.' | tee -a $LF
	fi

	if [ ! -x "Statement/GBK/$YESTERDAY" ]; then  
		echo "Making dirs GBK/$YESTERDAY" | tee -a $LF
		mkdir -p "Statement/GBK/$YESTERDAY/" 
	else
		echo "dir Statement/GBK/$YESTERDAY existed." | tee -a $LF
	fi
}

unzipFiles()
{
	targetFile=`ls Statement/GBK/$YESTERDAY/ | wc -l` 
	if [ "$targetFile" -ge '1' ];then
        	echo "GBK/$YESTERDAY/*.csv found, will not unzip file"
	else
		if [ -f "download/$YESTERDAY/${YESTERDAY}_zhye-yh-cqg.zip" ];then
			echo "Finding *.zip then unzip them"| tee -a $LF
			find download -name "*.zip" -exec unzip -o -d Statement/GBK/$YESTERDAY {} \;
		else
       			echo "Zip file download/$YESTERDAY/${YESTERDAY}_zhye-yh-cqg.zip no found. Download failed" | tee -a $LF
			
		fi
	fi
}
clearFiles()
{
	echo "Clear up...*.zip"| tee -a $LF
	find download -name "*.zip" -exec rm -f {} \;
}

transaferFiles()
{
	targetFile=`ls Statement/GBK/$YESTERDAY/ | wc -l` 
	if [ "$targetFile" -ge '1' ];then
		echo "Encoding start..." | 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
	else
		echo "GBK/$YESTERDAY/$YESTERDAY/.csv files no found" | tee -a $LF
		errorReport
	fi

}

zipFiles()
{
	if [ ! -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		echo "Zipping files into $YESTERDAY.Statement.zip" | tee -a $LF
		zip Statement/zip/$YESTERDAY.Statement.zip Statement/utf8/$YESTERDAY/*
	else
		echo "Found zip file will not zip them" | tee -a $LF
	fi
}

sendingFiles()
{
	echo "Sending $YESTERDAY.Statement.zip to someone and simon" | tee -a $LF
	echo "$YESTERDAY 对账单已发送" |mail -s "Statements for $YESTERDAY" -a Statement/zip/$YESTERDAY.Statement.zip -c someone@address.com me@email.com 
}

sendingSingleFile()
{
	targetFile=`find Statement/utf8/${YESTERDAY}/ -name "${YESTERDAY}_jymx-zjtg*"`
	echo "$YESTERDAY 对账单已发送" |mail -s "Statements for $YESTERDAY" -a $targetFile -c someone@address.com me@email.com 
}
errorReport(){
	echo "对账单发送错误了快查看" |mail -s "ERROR:Statements sending error" -a /var/log/statement/daily/statement.log  alert@email.com  
	echo "对账单发送错误" | tee -a $LF
	echo '-------------------------------' >> $LF
	exit 1
}
main()
{
	echo 'Start... '`date +%Y%m%d-%H:%M:%S` | tee -a $LF
	echo "Moving to $CW" | tee -a $LF
	cd $CW
	download
	makedirs
	unzipFiles
	transaferFiles
	zipFiles
	if [ ! -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		errorReport
	else
		#sendingFiles
		sendingSingleFile
		clearFiles
	fi
	echo 'Done...'`date +%Y%m%d-%H:%M:%S` >> $LF
	echo '-------------------------------' >> $LF
}

main

DOWNLOAD FILES AND TRANSCODING THEN MAILING THEM ALL AUTOMATICALLY

#! /bin/bash
#version 2.0
#auther simon@codewalker.me
LF=/var/log/statement/daily/statement.log

YESTERDAY=`date +%Y%m%d -d 'yesterday'`
if [ $1 ]; then
	YESTERDAY=$1
fi

download ()
{
	if [ -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		echo "Already sending $YESTERDAY.statement" | tee -a $LF
		read -n1 -p "Do you want force to send mail [Y|N]? " current_input
		case $current_input in
		Y|y)
			echo "Downloading ${YESTERDAY}_zhye-yh-cqg.zip file" | tee -a $LF
			curl "http://www.download.com/url"
		;;
		N|n)
			echo 'Choice no. exit' | tee -a $LF
			exit 0
		;;
		esac
			
	else
		if [ ! -f "download/$YESTERDAY/$YESTERDAY"_zhye-yh-cqg.zip ];then
			echo "Downloading ${YESTERDAY}_zhye-yh-cqg.zip file" | tee -a $LF
			curl "http://www.download.com/url"
		else
			echo "Found ${YESTERDAY}_*.zip zips will not download..." | tee -a $LF
		fi
	fi
}

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

	if [ ! -x "Statement/zip/" ]; then  
		echo "Making dir zip" | tee -a $LF
		mkdir -p "Statement/zip/" 
	else
		echo 'dir Statement/zip/ existed.' | tee -a $LF
	fi

	if [ ! -x "Statement/GBK/$YESTERDAY" ]; then  
		echo "Making dirs GBK/$YESTERDAY" | tee -a $LF
		mkdir -p "Statement/GBK/$YESTERDAY/" 
	else
		echo "dir Statement/GBK/$YESTERDAY existed." | tee -a $LF
	fi
}

unzipFiles()
{
	targetFile=`ls Statement/GBK/$YESTERDAY/ | wc -l` 
	if [ "$targetFile" -ge '1' ];then
        	echo "GBK/$YESTERDAY/*.csv found, will not unzip file"
	else
		if [ -f "download/$YESTERDAY/${YESTERDAY}_zhye-yh-cqg.zip" ];then
			echo "Finding *.zip then unzip them"| tee -a $LF
			find download -name "*.zip" -exec unzip -o -d Statement/GBK/$YESTERDAY {} \;
		else
       			echo "Zip file download/$YESTERDAY/${YESTERDAY}_zhye-yh-cqg.zip no found. Download failed" | tee -a $LF
			
		fi
	fi
}
clearFiles()
{
	echo "Clear up...*.zip"| tee -a $LF
	find download -name "*.zip" -exec rm -f {} \;
}

transaferFiles()
{
	targetFile=`ls Statement/GBK/$YESTERDAY/ | wc -l` 
	if [ "$targetFile" -ge '1' ];then
		echo "Encoding start..." | 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
	else
		echo "GBK/$YESTERDAY/$YESTERDAY/.csv files no found" | tee -a $LF
		errorReport
	fi

}

zipFiles()
{
	if [ ! -f "Statement/zip/$YESTERDAY.Statement.zip" ]; then
		echo "Zipping files into $YESTERDAY.Statement.zip" | tee -a $LF
		zip Statement/zip/$YESTERDAY.Statement.zip Statement/utf8/$YESTERDAY/*
	else
		echo "Found zip file will not zip them" | tee -a $LF
		errorReport
	fi
}

sendingFiles()
{
	echo "Sending $YESTERDAY.Statement.zip to 2406204350@qq.com and simon" | tee -a $LF
	echo "$YESTERDAY 对账单已发送" |mail -s "Statements for $YESTERDAY" -a Statement/zip/$YESTERDAY.Statement.zip -c mail@address.com  
}
errorReport(){
	echo "对账单发送错误了快查看" |mail -s "ERROR:Statements sending error" -a /var/log/statement/daily/statement.log  alert@mail.com  
	echo "对账单发送错误" | tee -a $LF
	echo '-------------------------------' >> $LF
	exit 1
}
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
		clearFiles
	fi
	echo 'Done...'`date +%Y%m%d-%H:%M:%S` >> $LF
	echo '-------------------------------' >> $LF
}

main

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

Fadada(法大大) sucks!!!

最近在对接法大大的接口,看给的案例完全没有封装看到这种没有Class 没有 function的代码就像吃了一勺苍蝇一样难受。

最后自己封装一个class FDD感觉舒坦多了.

EOF

How to enable IPv6 on Centos 6.X

Step 1.
Check IPv6 module is enable for Kernel

lsmod | grep ipv6

step 2.Enable IT.
2.1
##notice may file name is different##
Editing the file /etc/modprobe.d/disable_ipv6.conf
Change
options ipv6 disable=0
to
options ipv6 disable=1

2.2
Editing the file /etc/sysconfig/network
Change
NETWORKING_IPV6=no
to
NETWORKING_IPV6=yes

step 3 rebooting your server

step 4
configure kernel parameters to enable IPv6

sysctl -w net.ipv6.conf.all.disable_ipv6=0
then reboot

step 5
Checking if it works.

sysctl -a | grep ipv6

then it will outputting something like net.ipv6.confXXXXXXX = 0.

all done.

cover jks to pem using key tool

step 1. cover file.jks to file.p12 keytool -importkeystore -srckeystore filename.jks -destkeystore new.filename.p12 -srcstoretype jks -deststoretype pkcs12

step 2.1 cover file.p12 to pem with password openssl pkcs12 -in new.filename.p12 -out file.pem

step 2.1 cover file.p12 to pem without password openssl pkcs12 -nodes -in new.filename.p12 -out file.pem

Remove old backups automatically over 86400 mins

Remove old backups automatically over 86400 mins when disk used over 90% & send mail to named E-mail.

SERVER_NAME=`hostname`
vvv=`df -h|awk -F ' ' '{print $5}'|tail -n1`
len=${#vvv}
newLen=$(( len - 1 ))
num=${vvv:0:newLen}
if [[ num -gt 90 ]]; then
        find /path/to/dir -name '*tar.gz' -cmin  +86400 -exec rm {} \;
        find /path/to/another/dir -name '*tar.gz' -cmin  +86400 -exec rm {} \;
        echo "我们已经使用了 $vvv 空间了注意注意 然后删除了很多文件哦" |mail -s "Disk usage of $SERVER_NAME  server" anMail@box.com
fi

记——2016(这不是年总结)

你好亲爱的自己:

今年一跨入2017年, 你就可以说是30岁了. 是啊, 时间过得很快, 在你的认知里面觉得现在有了30岁人的样子了吗?

现在刚刚你和朋友去酒吧跨万年, 这不是你往常的风格. 我知道你想要的是和爱人待在一起就好.

哥们儿, 你知道吗? 现在是两点三十分. 现在你还在写东西自言自语, 这也不是你的风格. 但你为什么还要这样?

也许, 现在你想的是内心中有很多的快乐. 今年你完成了许许多多的大事, 发生的让自己完全无法言喻的值得开心的事情. 这些事情都是在年末逐渐慢慢发酵. 这是你自己赢得的礼物.
最大最大的幸福是你自己找到了一个你爱的人, 同时她也是很爱你的那个人. 我很为你高兴. 这就是这29年来最大最大的事情. 小伙子 好好的去珍惜她 爱护她 守护着她, 不要应为小盆友的任性而去吼她, 不要因为她爱玩就想入非非. 你要知道, 你比她大了不少岁数你一定要忍着很多事, 家庭的责任都由你来负责了. 你需要做的是放下心, 就像她经常告诫你不要因为以前的那些事情左右了你的情绪, 人都是不同的. 我知道你爱她, 爱她就要相信她. 为了你们俩将来的生活而奋斗, 让你们俩过上更好的日子. 现在你是两个人了 不要像之前你一个人过得随意, 你也不是万能的. 既然你们在一起了家庭方面的事情需要你们俩共同来承担. 我知道你爱她, 我也知道你很久很久没有说过爱一个人, 甚至喜欢也不想说了. 我知道你每次给她说爱她的时候都是很认真很认真的. 你有时候就是太重感情, 所以才导致了没有人能走进你的里面, 那是你受伤了之后只会自己一个人独自的舔舐伤口. 现在好多了, 不是有那么个人来为你分担吗? 不是她很多时候也在让着你吗? 你知道她脾气暴躁 你知不知道她为你收敛了多少? 这是你们互相影响的结果啊. 你看, 我们来算一算截止今天2017年01月01日你们认识一共是2个月14天\75天\6480000Mins 你们发展的好快, 你知道的. 你曾今绝对不会 不可能是那种一见钟情的人. 你曾今的标准 12345都到哪里去了? 不相信这些人理性人哪里去了? 想想看, 你遇见了她 这些东西怎么会都不见了. 在我的印象中按照曾今的那些想法的你怎么不见了? 都抛掉了, 仔细的想想看这是为什么? 承认你是个感性的人吧, 你的感性还是战胜了理性.
2017年01月01日03:08:31
现在还在这里话唠, 你是在想她吗? 以前你给自己写总结的时候是那么的理性只说重点, 把所有的话题都要归纳为重点词汇, 想想看你怎么今年变成了话唠. 好像是因为你喝了酒, 还在不断的想你爱的她吧. 是不是无时无刻的都想要和她在一起. 你完蛋了 兄弟…
今年的总结就留给你的感情生活, 确切的说. 我知道你是想把今年的总结全都留给她.
2017年01月01日03:20:58
现在就保存发布 洗澡躺下吧. 我知道你还是会在床上翻来覆去的想着她, 你个傻孩子 都要30岁的人了还会想着一个人睡不着. 傻瓜.