shell逐行读取excel并执行sql
背景:测试同学想根据一组user_id 获取token做测试,由于各种原因(数据量大,sql语句复杂),只能根据user_id一条条查,于是写了个脚本:
1, 先查询需要的user_id 导出到user_do.csv 文件
2,脚本(示例):
#!/bin/bash cat user_do.csv | while read line do echo "userId is : ${line}" cmd="select user_id,token from user.user_token where user_id=${line} limit 1" cnt=$(mysql -h127.0.0.1 -uroot -ppassword -s -e "${cmd}" 2>/dev/null | grep -v cnt ) if [[ -z "$cnt" ]] then echo result is null continue fi echo ${cnt} >> ok.txt done