| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #!/bin/sh
- usage() {
- echo "Usage: $0 -s server -t \"title\" -c \"content\" [-r reward] [-l level] [-m money]"
- echo "Or (backward compatible): $0 serNum \"title\" \"content\" [reward] [level] [money]"
- exit 1
- }
- # Default values
- reward=0
- level=0
- money=0
- # Parse options
- while getopts "s:t:c:r:l:m:h" opt; do
- case $opt in
- s) serNum="$OPTARG" ;;
- t) title="$OPTARG" ;;
- c) content="$OPTARG" ;;
- r) reward="$OPTARG" ;;
- l) level="$OPTARG" ;;
- m) money="$OPTARG" ;;
- h) usage ;;
- *) usage ;;
- esac
- done
- # If no options provided, fall back to positional (backward compatibility)
- if [ -z "$serNum" ]; then
- serNum="$1"
- title="$2"
- content="$3"
- reward="${4:-0}"
- level="${5:-0}"
- money="${6:-0}"
- fi
- # Validate required
- if [ -z "$serNum" ]; then
- echo "server id is required"
- usage
- fi
- # Basic URL-encode for a few characters (space, &, ?, =, +)
- # This is not a full encoder but handles common problematic chars for URLs in this script.
- urlencode() {
- local s="$1"
- s=$(printf '%s' "$s" | sed -e 's/ /%20/g' -e 's/&/%26/g' -e 's/?/%3F/g' -e 's/=/ %3D/g' -e 's/+/ %2B/g')
- # Trim accidental spaces introduced above
- s=$(printf '%s' "$s" | sed 's/ */ /g')
- printf '%s' "$s"
- }
- # ...existing code... (server list lookup)
- url=""
- ro=""
- for server in `cat /data/shell/jenkins/serverlist`;do
- attr1=`echo $server | cut -d',' -f1`
- attr2=`echo $server | cut -d',' -f2`
- attr3=`echo $server | cut -d',' -f3`
- if [[ $attr1 == $serNum ]];then
- url=$attr2
- ro=$attr3
- break
- fi
- done
- if [[ $url == "" ]];then
- echo "服务器未配置,需要手动添加"
- exit 0
- fi
- echo "传入的服务器id:${serNum}"
- echo "传入的邮件标题:${title}"
- echo "传入的邮件内容:${content}"
- echo "传入的邮件奖励:${reward}"
- echo "传入的等级筛选:${level}"
- echo "传入的充值筛选:${money}"
- # URL-encode title and content (basic)
- enc_title=$(urlencode "${title}")
- enc_content=$(urlencode "${content}")
- if [[ $reward == "0" ]];then
- url="$url/gm/mail?type=add&id=1&title=$enc_title&content=$enc_content"
- else
- url="$url/gm/mail?type=add&id=1&title=$enc_title&content=$enc_content&reward=$reward"
- fi
- # Query uids and send mails
- uids=$(mysql -uroot -p123456 "$ro" -N -e "select uid from role where base_level>=${level} and total_recharge>=${money};")
- for id in ${uids}; do
- curl "${url}&uid=${id}"
- done
- echo "-----执行完毕-----"
|