这是我用来将一些文档导出到elasticsearch但没有运气的脚本
#!/bin/ksh
set -v
trap read debug
date=$(date +%Y-%m-%d);
echo $date;
config_file="/home/p.sshanm/reports_elastic.cfg";
echo $config_file;
URL="http://p-acqpes-app01.wirecard.sys:9200/reports-"$date"";
echo $URL;
find /transfers/documents/*/done/ -type f -name "ABC-Record*_${date}*.csv"|
while IFS='' read -r -d '' filename
do
echo "filename : ${filename}"
var=$(base64 "$filename"| perl -pe 's/\n//g');
#if i use below it will fail as argument too long , so i used with curl option @
# var1= $(curl -XPUT 'http://localhost:9200/reports-'$date'/document/reports?pipeline=attachment&pretty' -d' { "data" : "'$var'" }')
var1=$(curl -X PUT -H "Content-Type: application/json" -d @- "$URL" >>CURLDATA
{ "data": "$var" }
CURL_DATA)
done;
如果我在它下面使用
var1= $(curl -XPUT 'http://localhost:9200/reports-'$date'/document/reports?pipeline=attachment&pretty' -d' { "data" : "'$var'" }')
将失败,如下所示,因此我使用curl选项@
论证太长了
答案 0 :(得分:1)
您从stdin
读取的语法错误,here-doc string应该是(<<
),并且限制器在两个地方都使用CURL_DATA
不匹配
curl -X PUT -H "Content-Type: application/json" -d @- "$URL" <<CURL_DATA
{ "data": "$var" }
CURL_DATA