我正在创建一个脚本,以从表中获取计数,并将其存储在文本文件中,并触发邮件以使团队知道当天表中的计数
#!/bin/bash
today=$(date +%d-%m-%Y)
> /tmp/score_cnt.txt
FILE="/tmp/score_cnt.txt"
sqlplus -S user/Pass@service<< EOF
set heading off;
spool $FILE
select count(*) from score_tbl;
spool off;
count= cat /tmp/score_cnt.txt
if ($count eq O)
then (
echo "Dear All,
URGENT! Please check if the ETL execution is success as the todays count in Table is 0
") | mailx -S smtp=XX:XX:XX:XX:XX -s "COUNT FOR $today : $count" -a /tmp/score_cnt.txt abc@gmail.com
else
echo "Today's count in table is $count!"
| mailx -S smtp=XX:XX:XX:XX:XX -s "COUNT FOR $today : $count" -a /tmp/score_cnt.txt abc@gmail.com
exit;
EOF
但是由于某些语句未执行,因此我面临以下问题。有人可以让我知道脚本中的错误吗。
++ date +%d-%m-%Y
+ today=14-03-2020
+ FILE=/tmp/score_cnt.txt
+ sqlplus -S user/Pass@service<< EOF
19127227
SP2-0734: unknown command beginning "count= cat..." - rest of line ignored.
SP2-0042: unknown command "if ( eq O)" - rest of line ignored.
SP2-0042: unknown command "then (" - rest of line ignored.
SP2-0734: unknown command beginning "echo "Dear..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "URGENT! Pl..." - rest of line ignored.
SP2-0734: unknown command beginning "") | mailx..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0042: unknown command "else" - rest of line ignored.
SP2-0734: unknown command beginning "echo "Toda..." - rest of line ignored.
SP2-0734: unknown command beginning "| mailx -S..." - rest of line ignored.
答案 0 :(得分:0)
尝试:
#!/bin/bash
today=$(date +%d-%m-%Y)
> /tmp/score_cnt.txt
FILE="/tmp/score_cnt.txt"
sqlplus -S user/Pass@service<< EOF
set heading off;
spool $FILE
select count(*) from score_tbl;
spool off;
EOF
count=$(cat /tmp/score_cnt.txt)
if ((count == O)); then
echo "Dear All,
URGENT! Please check if the ETL execution is success as the todays count in Table is 0
" |
mailx -S smtp=XX:XX:XX:XX:XX -s "COUNT FOR $today : $count" -a /tmp/score_cnt.txt abc@gmail.com
else
echo "Today's count in table is $count!" |
mailx -S smtp=XX:XX:XX:XX:XX -s "COUNT FOR $today : $count" -a /tmp/score_cnt.txt abc@gmail.com
fi
但是我想你可以:
count=$(sqlplus -S user/pass@server <<EOF
set heading off;
select count(*) from score_tbl;
EOF
)