Last active
March 30, 2018 00:34
-
-
Save gotnix/4326286 to your computer and use it in GitHub Desktop.
Revisions
-
gotnix revised this gist
Jan 15, 2013 . 1 changed file with 68 additions and 67 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,71 +1,72 @@ #!/bin/bash # Zabbix alert script via E-mas. #curl -v -i -H "Accept: application/json" -X POST --data-urlencode 'jsondata={"cmd":"1001","username":"UserName","userpassword":"PassWord","key":"EMASKEYS","timestamp":"","channel_id":"5","mobiles":"'$tz'","sendtime":"","smscontent":"Order:T-343651581-Status: Curl-Shipped","srccharset":"GBK","smsid":"201211022014"}' http://10.0.0.1/EMAS/sms_server.jsp CURL='/usr/bin/curl -w %{http_code} -s -H "Accept: application/json" -H "Content Type: application/json" -X POST --data-urlencode' EMAS_URL="http://10.0.0.1/EMAS/sms_server.jsp" CHID_CM=5 CHID_CU=4 CHID_CN=7 EMAS_USER="UserName" EMAS_PW="PassWord" TIME_STAMP=$(date +%Y%m%d%H%M%S) EMAS_CH=0 CELL_PHON=${1} MESS_ORIG=${3} MESS=$(echo ${3} | iconv -f UTF8 -t GBK) SMSID=$(date +%s) ################################################################ # 检查要发送的短信中是否包含URL需要转义的特殊字符, # 如果有% , 替换成ASCII 表示, 并把短信的字符集从UTF8 转换成 GBK. # # 以下代码把这个功能实现得很土,把curl 的参数 -d 换成 # --data-urlencode 完美解决URL 特殊字符需要转义的问题. #if [[ ${MESS_ORIG} =~ .*%.* ]] ; then # HANDLE=$(eval "echo ${MESS_ORIG} | sed s/%/%25/g") # MESS=$(echo ${HANDLE} | iconv -f UTF8 -t GBK) #else # MESS=$(echo ${MESS_ORIG} | iconv -f UTF8 -t GBK) #fi ################################################################ function send_sms() { # Parameter1 is E-mas channel ID. local ch_id=$1 local phone_num=$2 local emas_json='jsondata={"cmd":"1001","username":"'"${EMAS_USER}"'","userpassword":"'"${EMAS_PW}"'","key":"EMASKEYS","timestamp":"'"${TIME_STAMP}"'","channel_id":"'"${ch_id}"'","mobiles":"'"${CELL_PHON}"'","sendtime":"","smscontent":"'"${MESS}"'","srccharset":"GBK","smsid":"'"${SMSID}"'"}' local send="${CURL} '${emas_json}' ${EMAS_URL} | grep 0" local result=$(eval ${send}) logger -s -t zabbix_sms "${CELL_PHON} send status is ${result}" # ToDo: Confirm the message send status; # Confirm curl http code. } # 检查手机号码位数 if [ ${#CELL_PHON} -ne 11 ] ; then logger -s -t zabbix_sms "Please check you cell phone number." exit 44 fi case ${CELL_PHON:0:3} in # 截取手机号前3 位判断运营商号段 13[4-9]|15[0-2]|15[7-9]|18[23]|18[78]) # 中国移动号段 EMAS_CH="${CHID_CM}" send_sms ${EMAS_CH} ;; 1[35]3|18[01]|189) # 中国电信号段 EMAS_CH="${CHID_CN}" send_sms ${EMAS_CH} ;; 13[0-2]|15[56]|18[56]) # 中国联通手机发送通道 EMAS_CH="${CHID_CN}" send_sms ${EMAS_CH} ;; *) echo "Chechk your cell phone number." ;; esac exit $? -
gotnix revised this gist
Jan 15, 2013 . 1 changed file with 62 additions and 63 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,72 +1,71 @@ #!/bin/bash # Remove the expired files. # # find /tmp/test/ -mtime +6 -delete # # Note: # [root@py-erp03-116 script]# find /var/log/apps/ -uid 2 -mtime +3 | \ # xargs -t -I {exp} rm -f {exp} # rm -f /var/log/apps/ # rm: cannot remove `/var/log/apps/': Is a directory # Or # [root@py-erp03-116 script]# find /var/log/apps/ -uid 2 -mtime +3 -delete # /bin/find: cannot delete `/var/log/apps/': Directory not empty # # So, the option ${FIND_OPT} must include "-type f", although do it like this will # remaining empty directory. # ################################################################################ FIND="/bin/find" FIND_DIR=("/var/www/remote_data/statics/tmp/export/" \ "/var/www/remote_data/original_images/goods_pic_exp/" \ "/var/www/remote_data/goods_pic_exp/") FIND_OPT="-uid 2 -type f -mtime +" FIND_ACT="-delete" #FIND_DIR=("/tmp/a/" "/tmp/b/" "/tmp/c/") #FIND_OPT="-uid 2 -mmin +" #FIND_ACT='| xargs -t -i {d} ls -lhAF {d}' LOGGER="/usr/bin/logger" LOG_OPT="-s -t $0" ################################################################################ # Functions ################################################################################ rm_expf () { # arg1 is the directory of expired files. # arg2 is expired days. local pd_exp=$1 local expdays=$2 cd ${pd_exp} || { ${LOGGER} ${LOG_OPT} "${pd_exp} isnot exist or permission denied." && \ exit 1 } && ${FIND} ${pd_exp} ${FIND_OPT}${expdays} ${FIND_ACT} } ################################################################################ # Main ################################################################################ for (( i=0 ; i<${#FIND_DIR[@]} ; i++ )) do case ${i} in 0) # /var/www/remote_data/statics/tmp/export/ delete files before 3 days. rm_expf ${FIND_DIR[i]} 3 ;; 1|2) # /var/www/remote_data/original_images/goods_pic_exp/ and # /var/www/remote_data/goods_pic_exp/ delete files before 10 days. rm_expf ${FIND_DIR[i]} 10 ;; *) echo "Check \${FIND_DIR[@]} Array." exit 1 ;; esac done exit $? -
gotnix revised this gist
Dec 26, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ function send_sms() { local emas_json='jsondata={"cmd":"1001","username":"'"${EMAS_USER}"'","userpassword":"'"${EMAS_PW}"'","key":"EMASKEYS","timestamp":"'"${TIME_STAMP}"'","channel_id":"'"${ch_id}"'","mobiles":"'"${CELL_PHON}"'","sendtime":"","smscontent":"'"${MESS}"'","srccharset":"GBK","smsid":"'"${SMSID}"'"}' local send="${CURL} '${emas_json}' ${EMAS_URL} | grep 0" local result=$(eval ${send}) logger -s -t zabbix_sms "Emas_smsid-${SMSID} Send to ${CELL_PHON} Via channel ${ch_id} Status is ${result}" # ToDo: Confirm the message send status; # Confirm curl http code. } -
gotnix revised this gist
Dec 26, 2012 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ #!/bin/bash # Zabbix alert script via E-mas. #curl -v -i -H "Accept: application/json" -X POST --data-urlencode 'jsondata={"cmd":"1001","username":"UserName","userpassword":"PassWord","key":"EMASKEYS","timestamp":"","channel_id":"5","mobiles":"'$tz'","sendtime":"","smscontent":"Order:T-343651581-Status: Curl-Shipped","srccharset":"GBK","smsid":"201211022014"}' http://10.0.0.1/EMAS/sms_server.jsp CURL='/usr/bin/curl -w %{http_code} -s -H "Accept: application/json" -H "Content Type: application/json" -X POST --data-urlencode' EMAS_URL="http://10.0.0.1/EMAS/sms_server.jsp" CHID_CM=5 CHID_CU=4 @@ -13,18 +13,22 @@ TIME_STAMP=$(date +%Y%m%d%H%M%S) EMAS_CH=0 CELL_PHON=${1} MESS_ORIG=${3} MESS=$(echo ${3} | iconv -f UTF8 -t GBK) SMSID=$(date +%s) ################################################################ # 检查要发送的短信中是否包含URL需要转义的特殊字符, # 如果有% , 替换成ASCII 表示, 并把短信的字符集从UTF8 转换成 GBK. # # 以下代码把这个功能实现得很土,把curl 的参数 -d 换成 # --data-urlencode 完美解决URL 特殊字符需要转义的问题. #if [[ ${MESS_ORIG} =~ .*%.* ]] ; then # HANDLE=$(eval "echo ${MESS_ORIG} | sed s/%/%25/g") # MESS=$(echo ${HANDLE} | iconv -f UTF8 -t GBK) #else # MESS=$(echo ${MESS_ORIG} | iconv -f UTF8 -t GBK) #fi ################################################################ function send_sms() { # Parameter1 is E-mas channel ID. -
gotnix revised this gist
Dec 19, 2012 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,19 @@ EMAS_PW="PassWord" TIME_STAMP=$(date +%Y%m%d%H%M%S) EMAS_CH=0 CELL_PHON=${1} MESS_ORIG=${3} #MESS=$(echo ${3} | iconv -f UTF8 -t GBK) SMSID=$(date +%s) # 检查要发送的短信中是否包含URL需要转义的特殊字符, # 如果有% , 替换成ASCII 表示, 并把短信的字符集从UTF8 转换成 GBK. if [[ ${MESS_ORIG} =~ .*%.* ]] ; then HANDLE=$(eval "echo ${MESS_ORIG} | sed s/%/%25/g") MESS=$(echo ${HANDLE} | iconv -f UTF8 -t GBK) else MESS=$(echo ${MESS_ORIG} | iconv -f UTF8 -t GBK) fi function send_sms() { # Parameter1 is E-mas channel ID. -
gotnix revised this gist
Dec 18, 2012 . No changes.There are no files selected for viewing
-
gotnix created this gist
Dec 18, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ #!/bin/bash # Zabbix alert script via E-mas. #curl -v -i -H "Accept: application/json" -X POST -d 'jsondata={"cmd":"1001","username":"UserName","userpassword":"PassWord","key":"EMASKEYS","timestamp":"","channel_id":"5","mobiles":"'$tz'","sendtime":"","smscontent":"Order:T-343651581-Status: Curl-Shipped","srccharset":"GBK","smsid":"201211022014"}' http://10.0.0.1/EMAS/sms_server.jsp CURL='/usr/bin/curl -w %{http_code} -s -H "Accept: application/json" -H "Content Type: application/json" -X POST -d' EMAS_URL="http://10.0.0.1/EMAS/sms_server.jsp" CHID_CM=5 CHID_CU=4 CHID_CN=7 EMAS_USER="UserName" EMAS_PW="PassWord" TIME_STAMP=$(date +%Y%m%d%H%M%S) EMAS_CH=0 CELL_PHON=${1} MESS=$(echo ${3} | iconv -f UTF8 -t GBK) SMSID=$(date +%s) function send_sms() { # Parameter1 is E-mas channel ID. local ch_id=$1 local phone_num=$2 local emas_json='jsondata={"cmd":"1001","username":"'"${EMAS_USER}"'","userpassword":"'"${EMAS_PW}"'","key":"EMASKEYS","timestamp":"'"${TIME_STAMP}"'","channel_id":"'"${ch_id}"'","mobiles":"'"${CELL_PHON}"'","sendtime":"","smscontent":"'"${MESS}"'","srccharset":"GBK","smsid":"'"${SMSID}"'"}' local send="${CURL} '${emas_json}' ${EMAS_URL} | grep 0" local result=$(eval ${send}) logger -s -t zabbix_sms "${CELL_PHON} send status is ${result}" # ToDo: Confirm the message send status; # Confirm curl http code. } # 检查手机号码位数 if [ ${#CELL_PHON} -ne 11 ] ; then logger -s -t zabbix_sms "Please check you cell phone number." exit 44 fi case ${CELL_PHON:0:3} in # 截取手机号前3 位判断运营商号段 13[4-9]|15[0-2]|15[7-9]|18[23]|18[78]) # 中国移动号段 EMAS_CH="${CHID_CM}" send_sms ${EMAS_CH} ;; 1[35]3|18[01]|189) # 中国电信号段 EMAS_CH="${CHID_CN}" send_sms ${EMAS_CH} ;; 13[0-2]|15[56]|18[56]) # 中国联通手机发送通道 EMAS_CH="${CHID_CN}" send_sms ${EMAS_CH} ;; *) echo "Chechk your cell phone number." ;; esac exit $?