#!/bin/bash
MYSQL='mysql -u*** -p*** -hws5 account'
tmp="tmp"
resultsource="resultsource"
resultdest="resultdest"
echo "select user_id,phone_num,email from user_accounts where length(user_id) = 11 limit 1"|${MYSQL} > ${tmp}
sed '1d' ${tmp} > ${resultsource}
> ${resultdest}
while read user_id phone_num email
do
echo ${user_id} `echo ROKID${phone_num}ACCOUNT`
echo -n ROKID${phone_num}ACCOUNT|md5sum|cut -d" " -f 1|tr [a-z] [A-Z]
echo ${user_id} `echo -n ROKID${phone_num}ACCOUNT|md5sum|cut -d" " -f |tr [a-z] [A-Z]` >> ${resultdest}
done < ${resultsource} #while read user_id phone_num_md5
#do
# echo "update user_accounts set phone_num = \"${phone_num_md5}\" where user_id = \"${user_id}\"" | $MYSQL
#done < ${resultdest}

上面红色加粗的语句,为正确的md5sum加密方法(特别注意前面echo -n 选项)

PS:MAC下在文件中执行上面红色加粗的选项,始终不能去掉字符串后面的回车符。

可通过xxd filename

或者od -c filename 查看是否有回车符

未完待续。。。

05-11 20:42