我的脚本拒绝在cron下工作,但是在手动执行时可以正常工作
#!/bin/bash
LOGFILE=/opt/xxx/scripts/rc.log
fUpMail() {
echo -e "Hello!\n\n$1 xx\n\nBest regards,\n\nCheck LLC 2k18" | mailx -s "$1 Rates were not imported" smone@smth.com
}
curDate=`date +%Y-%m-%d`
#postgres expression output being assigned to a variable
rateQ=`PGPASSWORD=xxxxxx psql -t -h xxx.xxx.228.134 -p 5433 -d axx2 -U axxx2bo << EOF
SELECT COUNT(id) FROM quote WHERE f_date = '$curDate'
EOF`
#same for demodb
rateDemo=`PGPASSWORD=xxx psql -t -h xx.xxx.42.14 -p 5432 -d axxxo -U acxxxxbo << EOF
SELECT COUNT(id) FROM quote WHERE f_date = '$curDate'
EOF`
#logging
printf "\n`date +%H:%M:%S` $curDate $rateQ $rateDemo\n" >> $LOGFILE
#check if rate value is not null
if [[ $(($rateQ)) != 0 ]] && [[ $(($rateDemo)) != 0 ]];
then
#posting a commentary into jira
curl -u xxx-support-bot:Rzq-xxx-xxx-gch -X POST --data '{"body": "'"$rateQ"' LIVE rates for '"$curDate"' were imported automatically'"\n"''"$rateDemo"' DEMO rates for '"$curDate"' were imported automatically"}' -H "Content-type: application/json" https://jira.in.xxx.com:443/rest/api/2/issue/xxxxxx-1024/comment >> $LOGFILE
else
#if rates were not imported
if [[ $(($rateQ)) == 0 ]];
then
echo "looks like LIVE rates for $curDate were not imported, please check manually!"
#sending a letter
fUpMail 'LIVE'
fi
if [[ $(($rateDemo)) == 0 ]];
then
echo "looks like DEMO rates for $curDate were not imported, please check manually!"
fUpMail 'DEMO'
fi
fi
cron发送以下消息:
/opt/xxx/scripts/ratecheck.sh: line 25: Timing is on. 6543 Time: 4.555 ms: syntax error: invalid arithmetic operator (error token is ". 6543 Time: 4.555 ms")
第25行是
if [[ $(($rateQ)) != 0 ]] && [[ $(($rateDemo)) != 0 ]];
能否请人帮忙解释一下这里出什么问题了?
答案 0 :(得分:0)
从Hosting stopping
Stopping JobHost
Singleton lock released (cafectoweretl/WebJobs.Internal.Blobs.Listener)
返回的数字不仅是纯数字,而且还会干扰您正在进行的类型转换。我认为您可以像这样删除多余的输出:
psql
请注意添加了rateQ=$(PGPASSWORD=xxxxxx psql -t -h xxx.xxx.228.134 -p 5433 -d axx2 -U axxx2bo -q -c "SELECT COUNT(id) FROM quote WHERE f_date = '$curDate'")
rateDemo=$(PGPASSWORD=xxx psql -t -h xx.xxx.42.14 -p 5432 -d axxxo -U acxxxxbo -q -c "SELECT COUNT(id) FROM quote WHERE f_date = '$curDate'")
标志:
-q -安静
指定psql应该安静地工作。默认情况下,它打印欢迎消息和各种信息输出。如果使用此选项,则不会发生任何情况。这对于-c选项很有用。这等效于将变量QUIET设置为on。
https://www.postgresql.org/docs/9.0/app-psql.html
我还用-q
替换了您的老式反引号,并将SQL查询放入参数中。
如果这不能使其他输出静音,则可能还需要为运行cron作业的用户编辑$()
,并确保没有~/.psqlrc
行。