簡體   English   中英

語法錯誤:反引號替換 shell 腳本中的 EOF

[英]Syntax error: EOF in backquote substitution shell script

我有 shell 腳本執行一些 Athena 查詢當我運行腳本時,它顯示以下錯誤

Syntax error: EOF in backquote substitution

腳本代碼

#!/bin/bash
date ;
ruby <filename>.rb ;
echo "delete existing <table name>";
aws configure set region us-east-1;
aws athena start-query-execution \
--query-string "DROP TABLE IF EXISTS <table name>" \
--work-group "primary" \
--query-execution-context Database=<database>\
--result-configuration "OutputLocation=s3://<path>/";
echo "create external table "
SQL="CREATE EXTERNAL TABLE <table name>( user_id string, file_name string, file_type string, count string) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES ("separatorChar" = ",", "quoteChar" = "`", "escapeChar" = "\\") STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://<path>/\$client_id/'";
FINALSQL=$(echo $SQL | sed -e "s/\$client_id/$client_id/g");

echo "FINALSQL--> ${FINALSQL}";
aws athena start-query-execution \
--query-string "$FINALSQL"\
--work-group "primary" \
--query-execution-context Database=<dbname>\
--result-configuration "OutputLocation=s3://<path>/"
echo "generating report"
query="select  user_id,case file_type  when 'networkclick' then 'Click' when 'networkactivity' then 'Activity' when 'networkimpression' then 'Impression' when 'matchtables' then 'Sync Pixel'  else 'NA' end as file_type ,sum(cast(count as integer)) as count from gdpr.gdpr_access_result group by file_type,user_id";
output_location="s3://<path>/"
query_execution_id=$(aws athena start-query-execution \
    --region "$region" \
    --query-string "$query" \
    --result-configuration "OutputLocation=$output_location" \
    --query QueryExecutionId \
--output text)
echo "query_execution_id was $query_execution_id"

while true; do
    status=$(aws athena get-query-execution \
        --query-execution-id "$query_execution_id" \
        --query QueryExecution.Status.State \
    --output text)
    if [[ $status != 'RUNNING' ]]; then
        break
    else
        sleep 5
    fi
done

if [[ $status = 'SUCCEEDED' ]]; then
    result_location=$(aws athena get-query-execution \
        --query-execution-id "$query_execution_id" \
        --query QueryExecution.ResultConfiguration.OutputLocation \
    --output text)
    echo "result_location was $result_location"
    exec aws s3 cp "$result_location" -
else
    reason=$(aws athena get-query-execution \
        --query-execution-id "$query_execution_id" \
        --query QueryExecution.Status.StateChangeReason \
    --output text)
    echo "Query $query_execution_id failed: $reason" 1>&2;
    exit 1
fi
date ;

我錯過了什么嗎? 我花了一些時間找東西。

還不能確定問題。 我試過下面的命令

bash -n <filename.sh>

遇到兩個問題

在此處輸入圖像描述

我該如何解決?

這是錯誤的:

SQL="CREATE EXTERNAL TABLE <table name>( user_id string, file_name string, file_type string, count string) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES ("separatorChar" = ",", "quoteChar" = "`", "escapeChar" = "\\") STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://<path>/\$client_id/'";

甚至這里的語法高亮顯示了問題:雙引號不嵌套。 此外,雙引號內的`仍然會進行命令替換擴展。 反斜杠內部雙引號以及反引號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM