我正在编写一个后期会话shell脚本,我必须计算一个平面文件行数的目标,如果计数大于500,则发送通知相同的邮件。但是剧本中有一些错误。
DIR="/data/research_dev/inbfiles"
cd /data/research_dev/inbfiles
if [ "$(wc -l ff_invoicepreviewqueue1.csv)" > 500 ]; then
echo "Hi," > InvoicePreview.dat
echo " The row count of InvoicePreviewQueue is: " >> InvoicePreview.dat
#wc -l ff_invoicepreviewqueue1.csv >> InvoicePreview.dat
echo " " >> InvoicePreview.dat
echo " " >> InvoicePreview.dat
echo "Thanks and Regards," >> InvoicePreview.dat
echo "BI Support team." >> InvoicePreview.dat
mailx -s "Alert!! Count is out of limits!! " "correia.blossom@rexelholdingsusa.com" < InvoicePreview.dat
rm -f InvoicePreview.dat.dat
#
请帮我找出错误
答案 0 :(得分:1)
命令wc -l ff_invoicepreviewqueue1.csv
通常会返回带有文件名的计数,例如499 ff_invoicepreviewqueue1.csv
。因此,您无法将其与500进行比较。您可能会执行cat ff_invoicepreviewqueue1.csv|wc -l
之类的操作,而这只会返回计数。
另外,运算符大于“-gt”,“&gt;”可能不会工作。所以要重写你的if语句,它将是:
if [ "$(cat ff_invoicepreviewqueue1.csv|wc -l)" -gt 500 ]; then
# send mail
fi
请记住使用fi。
关闭if条件答案 1 :(得分:0)
谢谢你的帮助.. 我从sql server源加载了目标flatfile,然后在赋值任务中我分配了带有源成功行的工作流变量,在决策任务中,如果行大于500我称为script1,如果行少,我称为script2
Rows="$(cat /data/research_dev/inbfiles/ff_invoicepreviewqueue.txt|wc -l)"
echo "Hi," > InvoicePreview.dat
echo " The row count of InvoicePreviewQueue is: " >> InvoicePreview.dat
echo $Rows" Rows">> InvoicePreview.dat
echo " Please re run the process to correct the count " >> InvoicePreview.dat
echo " " >> InvoicePreview.dat
echo " " >> InvoicePreview.dat
echo "Thanks and Regards," >> InvoicePreview.dat
echo "BI Support team." >> InvoicePreview.dat
mailx -s "Alert!! The count of InvoicePreviewQueue is "$Rows"!! " "correia.blossom@rexelholdingsusa.com" < InvoicePreview.dat
rm -f InvoicePreview.dat.dat
#
还有一个脚本,如果计数小于500则执行并发送邮件。 谢谢大家的帮助!