top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Shell Script in post session command to count the target row count

0 votes
211 views

am writing a post session shell script where i have to count the target which is a flat file row count and if the count is greater then 500 then send a mail notifying the same. But there are some errors in the script.

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
#
posted Feb 9, 2015 by Sunil

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The command wc -l ff_invoicepreviewqueue1.csv would usually return count with the file name like, 499 ff_invoicepreviewqueue1.csv. So you cannot compare it with 500. You may do something like cat ff_invoicepreviewqueue1.csv|wc -l which will return only the count.

Also, operator for greater than is "-gt", ">" probably will not work. So to rewrite your if statement it will be:

if [ "$(cat ff_invoicepreviewqueue1.csv|wc -l)" -gt 500 ]; then

    # send mail

fi

Remember to close the if condition with fi.

answer Feb 11, 2015 by Shweta Singh
Similar Questions
0 votes

we have two informatica jobs that run parallel . one starts at 11.40 cet and it has around 300 informatica workflows in it out of which one is fact_sales. the other job runs at 3.40 cet and it has around 115 workflows in it many of which are dependent on fact_sales in term of data consistency. the problem is fact_sales should finish before certain workflows in process 2 starts for data to be accurate. but this doesnt happen generally. what we are trying to do is to split the process 2 in such a way that fact_sales dependent workflows run only after the fact_sales has finished . can you provide me a way to go about writing a unix shell script that check the status of this fact_sales and if it successfull then kicks off other dependent workflows and if not then it should send a failure mail.

Thanks

+3 votes
...