记一次简单的shell使用

写了一大堆话还是删了,还是来简单交代下任务背景及需求。
昨天上线了一个接收回调并处理订单数据的模块,测试不是特别充分,其中的bug导致部分数据处理不成功,大概100多条,所幸回调的数据被记录在日志里,并且数据库中能够看出哪些订单处理出错,所以现在需要模拟回调。

从日志中grep出数据,然后用curl模拟回调,grep出的数据格式如下:

1
2017-02-27 11:30:45,609 INFO [10.168.89.192:57188 http-bio-8080-exec-33] com.ins.car.common.aop.WebLogAspect.doAround(WebLogAspect.java:57) - CarOrderController.uniOrder 2017-02-27 11:30:45,609 {"company":"OFFICIAL","request_body":"jsonData=%7b%22businPrice%22%3a%221774.03%22%2c%22callUrl%22%3a%22http%3a%2f%2f10.40.130.139%2fcallback%22%2c%22carShipTax%22%3a%22360%22%2c%22cooperId%22%3a%2292998109037%22%2c%22customerName%22%3a%22%e5%bc%a0%e9%9b%aa%22%2c%22endDate%22%3a%222018-04-11%22%2c%22insurPrice%22%3a%22665%22%2c%22note%22%3a%22%22%2c%22outTime%22%3a%222017-02-27+11%3a30%3a29.0%22%2c%22payUrl%22%3a%22%22%2c%22no%22%3a%2220173706D000001322%22%2c%22startDate%22%3a%222017-04-12%22%2c%22state%22%3a%22payed%22%2c%22sumPrice%22%3a%222799.03%22%7d","query_str":"","callback_url":"http://10.40.130.139/callback"} ============> 2017-02-27 11:30:45,650 {"data":{"client_channel":0,"type":3,"order_id":"92998109037"},"return_message":"[通知]日期格式不正确,请重试!","return_code":-100}

从数据库中将需要处理的订单的单号取出来导到need_process.txt中,每行一个单号。

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
for order_id in `cat need_process.txt`
do
content=`grep $order_id data.log | grep '日期格式不正确' | egrep -o 'jsonData[^"]+'`
echo "$order_id =====> $content"
if [ -n $content ]; then
curl -XPOST https://www.abc.com/callback.do -d "$content"
fi
#echo "$order_id"
done

注意正则的使用。-o 表示只输出匹配正则的数据。

我知道是不会有人点的,但万一有人想不开呢!