Are you scare.

随着年岁的增加,随着社会阅历的丰富.
当你进入人生这场戏剧的剧场,
在窥视这幕布后面人性之后,
所感受到的Cthulhu式的恐惧感和无力感时.
年幼时心中的那些花朵,
早已不知在何时枯萎凋谢.
眼 不得不随着你的视野而打开;
脑 不得不随着你的经验而思考;
身 不得不随着你的体验而防御;
盔甲 不得不随着经历或未经历的事情而披上.
珍惜每一个应该珍惜的身边人,
即使你根本没有意识到他们或她们为了你付出了什么.
远离每一个应该远离的身边人,
即使你根本没有意识到他们或她们伤害你了什么.

即使身处黑暗的隧道之中,
但也不要忘记前方的光明
即使身处风雨之中,
但也不要忘记雨后的彩虹.

May God bless you & me.

EOF

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