在看一個(gè)外包的項(xiàng)目中發(fā)現(xiàn)一個(gè)shell文件,內(nèi)容為:
#!/bin/bash
if [[ -f 'a.txt' ]]
then
unlink 'a.txt'
fi
pushurl='https://test.cn//Home/AppCoupon/pushMsg?majorID='
database='/usr/local/mysql/bin/mysql -uaacoupon -pe4oo23gUnj7cipeubj'
sql="select majorID,openID,ispush,id,cash_fee from a_order where ispush=0 "
#sql="select CONCAT(majorID.'|'.openID.'|'.ispush) from a_order"
#sql="select CONCAT(majorID,openID,ispush) from a_order"
res=`$database aacoupon -e "$sql"|awk 'NR>1'|awk '{print $0","}'`
echo $res>a.txt
sed -i "s#, #\n#g" a.txt
sed -i "s#,##g" a.txt
cat a.txt|while read line
do
majorID=`echo $line|awk -F" " '{print $1}'`
openID=`echo $line|awk -F" " '{print $2}'`
ispush=`echo $line|awk -F" " '{print $3}'`
id=`echo $line|awk -F" " '{print $4}'`
cash_fee=`echo $line|awk -F" " '{print $5}'`
ok=`curl -s $pushurl$majorID"&openID="$openID"&price="$cash_fee`
updatesql="update a_order set ispush=1 where id=$id"
$database aacoupon -e "$updatesql"
done
查了很久linux命令,大致明白了進(jìn)行了什么操作:1、判斷文件是否為普通文件,是則刪除2、進(jìn)行sql操作,將結(jié)果集按一定格式輸出到a.txt中3、處理a.txt文件,將','和', '替換4、按行讀取循環(huán)a.txt文件中的內(nèi)容,將每一行中的5個(gè)字段賦值到5個(gè)變量,然后進(jìn)行curl請(qǐng)求(這里請(qǐng)求了一個(gè)微信小程序的推送消息的方法),最后更新數(shù)據(jù)庫(kù)我大概明白了這個(gè)shell腳本是循環(huán)推送消息,可是我還是不太清楚這個(gè)shell腳本怎么去用,是要在服務(wù)器設(shè)置定時(shí)器調(diào)用這個(gè)shell腳本嗎?還是做如何使用的?我能提供的信息:1、這是一個(gè)微信小程序的后臺(tái)中的一個(gè)shell文件2、后臺(tái)是基于tp3.2框架3、我可能描述的很不清楚,大神可以繼續(xù)追問(wèn)
- 1 回答
- 0 關(guān)注
- 413 瀏覽
添加回答
舉報(bào)
0/150
提交
取消