您的位置:首页 > 运维架构 > Shell

shell应用实例子 啊啊

2017-03-29 16:44 232 查看
#!/bin/sh
filename=$1
if [ "${filename}q" == "q" ]
then
filename=eventop.csv
fi

#utf8转换
iconv -f gbk -t utf-8  eventop.csv > tool.tmp;
if [ $? -eq 0 ]
then
mv tool.tmp eventop.csv
fi
iconv -f gbk -t utf-8  tool.csv > tool.tmp;
if [ $? -eq 0 ]
then
mv tool.tmp tool.csv
fi

IFS=','
questtype=`sed -n '1p' $filename | awk -F ',' '{print $2}'`
questterm=`sed -n '2p' $filename | awk -F ',' '{print $2}'`
startime=`sed -n '3p' $filename | awk -F ',' '{print $2}'`
endtime=`sed -n '3p' $filename | awk -F ',' '{print $4}'`

startimestr=`date -d "${startime}" +%s`
endtimestr=`date -d "${endtime}" +%s`
endtimestr=$((endtimestr + 24 * 3600 - 1))

echo "$endtimestr" >&2
questbase=0x110001
questid=0x110000
questsumid=0x111000
questtype1=0x100000
if [ "${questtype}q" == "一周挑战q" ]
then
questid=0x210000
questbase=0x210001
questtype1=0x200000
elif [ "${questtype}q" == "阶段目标送送送q" ]
then
questbase=0x310001
questid=0x310000
questtype1=0x300000
fi

baseterm=$((questterm - 1))
hexquesttype=`printf %x $questtype1`
nexthextype=`printf %x $((questtype1 + 0x100000))`

echo "#删除期数相同的同类型任务"
if [ "${questtype}q" == "一挑战q" ]
then
echo "delete from my_tasknew.questforop_general_config where PID>=${questterm} and questtype=0x${hexquesttype};"
echo "delete from my_tasknew.questforop_config where period>=${questterm} and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
echo "delete from my_tasknew.questforopcond_config where period>=${questterm}  and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
echo "delete from my_tasknew.questforop_prize_config where period>=${questterm}  and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
else
#非一周挑战在这里写
echo "delete from my_tasknew.questforop_general_config where PID=${questterm} and questtype=0x${hexquesttype};"
echo "insert into my_tasknew.questforop_general_config values(0x${hexquesttype}, ${questterm}, $startimestr, $endtimestr); "
echo "delete from my_tasknew.questforop_config where period=${questterm} and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
echo "delete from my_tasknew.questforopcond_config where period=${questterm}  and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
echo "delete from my_tasknew.questforop_prize_config where period=${questterm}  and questid>0x${hexquesttype} and questid < 0x${nexthextype};"
fi

echo "#插入当前任务描述"
#echo "insert into my_tasknew.questforop_general_config values(0x${hexquesttype}, ${questterm}, $startimestr, $endtimestr); "

sed -n '5, $p' ${filename} | sed 's/^M/\/n/g' > tmpCsv

dos2unix tool.csv >&2
sed -i 's/^M/\/n/g' tool.csv
dos2unix tmpCsv >&2

questcount=0;
echo "#插入具体任务"
while read EV CType Count Desc Cond1Op Cond1 Cond2Op Cond2 ItemMan ItemWoman Means ItemCount DayOnly
do
#echo $EV $CType $Count $Desc $Cond1Op $Cond1 $Cond2Op $Cond2 $ItemMan $ItemWoman $Means $ItemCount >&2
ctype=0
if [ "${CType}q" == "完成数量q" ]
then
ctype=1
fi
count=1
if [ "${Count}q" != "q" ]
then
count=${Count}
fi
means=2
if [ "${Means}q" == "计时q" ]
then
means=1
fi
baseterm=$((baseterm + 1))
questid=$((questid + 1))
questsumid=$((questsumid+ 1))
hexquestsumid=`printf %x ${questsumid}`
tmpFind=`echo ${EV} | awk -F ' ' '{print $1}'`;
if [ "${questtype}q" == "一周挑战q" ]
then
questterm=$baseterm
questid=0x210001
fi
hexquestid=`printf %x ${questid}`
if [ "${tmpFind}q" == "q" ]
then
echo "手贱了吧,没配任务" >&2
exit 1
fi
findStr=`sed -n "/${tmpFind}-/p" tool.csv | awk -F '-' '{print $2}'`
IFS=' '
if [ "${findStr}q" == "q" ]
then
echo "配置错误" >&2
exit 1
fi
if [ "${tmpFind}" == "完成以上任务" ]
then
if [ "${questtype}q" != "挑战任务赢非卖q" ]
then
echo "配置错误:只有挑战赢非卖能有完成以上任务的选项" >&2
exit 0
fi

echo "insert into my_tasknew.questforop_config values(${questterm}, 0x${hexquestsumid}, 0xFF77, 0, 1, 0, 0, '完成全部挑战');"
for(( qid = $((questbase)); qid< ${questid}; qid++ ))
do
hexqid=`printf %x ${qid}`
echo "insert into my_tasknew.questforopcond_config values(${questterm}, 0x${hexquestsumid}, '${hexqid}', 'EQ', 0x${hexqid}); "
done
if [ "${ItemCount}q" != "q" ]
then
echo "insert into my_tasknew.questforop_prize_config values(${questterm}, 0x${hexquestsumid}, ${ItemMan}, ${ItemWoman}, ${means}, ${ItemCount});"
fi
break

fi
eventID=`echo ${findStr} | awk -F ',' '{print $1}'`
dayonly=0
if [ "${DayOnly}q" != "q" ]
then
dayonly=1
fi
echo "insert into my_tasknew.questforop_config values(${questterm}, 0x${hexquestid}, ${eventID}, ${ctype}, ${count}, 0, ${dayonly}, '${Desc}');"
condstr1=`echo ${findStr} | awk -F ',' '{print $2}'`
condstr2=`echo ${findStr} | awk -F ',' '{print $3}'`
extrocondcount=`echo ${findStr} | awk -F ',' '{print $4}' | awk -F '|' '{print NF}'`
#约束1中有数值
if [ "${Cond1}q" != "q" ]
then
CondOp="EQ"
if [ "${Cond1Op}q" == "大于等于q" ]
then
CondOp="GE"
fi
echo "insert into my_tasknew.questforopcond_config values(${questterm}, 0x${hexquestid}, '${condstr1}', '${CondOp}', ${Cond1});"
fi
#约束2中有数值
if [ "${Cond2}q" != "q" ]
then
CondOp="EQ"
if [ "${Cond2Op}q" ==  "大于等于q" ]
then
CondOp="GE"
fi
echo "insert into my_tasknew.questforopcond_config values(${questterm}, 0x${hexquestid}, '${condstr2}', '${CondOp}', ${Cond2});"
fi
#extra有额外的约束数据直接写入数据库,此约束使用|分隔的
for(( i = 1; i <= ${extrocondcount}; i++))
do
extstr=`echo ${findStr} | awk -F ',' '{print $4}' | awk -F '|' '{print $"'$i'"}'`
extname=`echo $extstr | awk -F ";" '{print $1}'`
extop=`echo $extstr | awk -F ";" '{print $2}'`
extvalue=`echo $extstr | awk -F ";" '{print $3}'`
echo "insert into my_tasknew.questforopcond_config values(${questterm},  0x${hexquestid}, '${extname}', '${extop}', ${extvalue});"
done
#如果是挑战赢非卖,就要写相应的伴生任务
if [ "${questtype}q" == "挑战任务赢非卖q" ]
then
echo "insert into my_tasknew.questforop_config values(${questterm}, 0x${hexquestsumid}, 0xFF77, 0, 1, 0, 0, '完成挑战$(($questid - $questbase + 1))');"
echo "insert into my_tasknew.questforopcond_config values(${questterm}, 0x${hexquestsumid}, '${hexquestid}', 'EQ', 0x${hexquestid}); "
if [ "${ItemCount}q" != "q" ]
then
echo "insert into my_tasknew.questforop_prize_config values(${questterm}, 0x${hexquestsumid}, ${ItemMan}, ${ItemWoman}, ${means}, ${ItemCount});"
fi
else
if [ "${ItemCount}q" != "q" ]
then
echo "insert into my_tasknew.questforop_prize_config values(${questterm}, 0x${hexquestid}, ${ItemMan}, ${ItemWoman}, ${means}, ${ItemCount});"
if [ "${questtype}q" == "一周挑战q" ]
then
echo "insert into my_tasknew.questforop_general_config values(0x${hexquesttype}, ${questterm}, $((startimestr + questcount * 7 * 24 * 3600)), $((startimestr + (questcount+1) * 7 * 24 * 3600 - 1)));"
questcount=$((questcount+1))
fi
fi
fi
IFS=','
echo ""
echo ""
done < tmpCsv

rm -rf tmpCsv
rm -rf tool.tmp
echo "clean " >&2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: