[英]Error executing the commands in the script
我正在創建一個腳本來從表中獲取計數,將它存儲在一個文本文件中並觸發一封郵件,讓團隊知道當天表中的計數
#!/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.
嘗試:
#!/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
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.