【发布时间】:2021-05-28 14:13:53
【问题描述】:
我正在尝试根据记录数检查表格并发送电子邮件。如果特定日期的记录为零,则将发送成功电子邮件。如果特定日期有任何记录,则错误消息应该消失。 我的问题是 - 正在发生相反的情况。即使没有记录,也会发出错误邮件。
下面是脚本
#!/bin/bash
export PGPASSWORD=xyz
TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
mailid='xyz@gmail.com'
cd /opt/postgres/pgsql/bin
vartest=`./psql -U user -h host -p port umrm -t -c "select count(*) from dataprocess_errors where error_date = current_date"` >> /opt/rmapp/test_error.log
if [$vartest -eq 0]
then
echo 'Files processed without errors' | mutt -s "Processing Success `date`" $mailid $attached >> /opt/rmapp/test_error.log
else
error=`./psql -U user -h host -p port umrm-t -c "select count (*) from dataprocess_errors where error_date = current_date and error_message like '%More than 25 employees%';"` >> /opt/rmapp/test_error.log
if [$error -eq 0]
then
echo 'Please check the table and fix the errorneous records' | mutt -s "Alert!! $vartest records failed in processing `date`" $mailid $attached >> /opt/rmapp/test_error.log
else
echo 'Please check the table' | mutt -s "Alert!!! processing stopped `date`" $mailid $attached >> /opt/rmapp/test_error.log
fi
fi
echo "Error Check completed at : $TIMESTAMP" >> /opt/rmapp/test_error.log
else 部分中的第二个 if 条件是根据变量“error”的输出来识别不同类型的错误。
我是 shell 脚本的菜鸟,所以请帮忙。 提前感谢所有帮助。
【问题讨论】:
-
您的连接字符串在此问题中可见。 :O
-
这是一个虚拟连接字符串:D
-
将您的代码粘贴到shellcheck.net 以获得语法错误帮助。
-
感谢帮助
标签: postgresql shell