Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 他们正在逃离他们。也许我误解了这个问题。您希望将$x替换为for循环中的值,还是将其保留为$x?如果是这样的话,for循环的原因是什么?正如我所说的,这将导致脚本认为第一个变量是脚本的结尾。这是一次真正的运行,而脚本并不这么认为。你用的是什么样的系统?你试_Linux_Bash - Fatal编程技术网

Linux 他们正在逃离他们。也许我误解了这个问题。您希望将$x替换为for循环中的值,还是将其保留为$x?如果是这样的话,for循环的原因是什么?正如我所说的,这将导致脚本认为第一个变量是脚本的结尾。这是一次真正的运行,而脚本并不这么认为。你用的是什么样的系统?你试

Linux 他们正在逃离他们。也许我误解了这个问题。您希望将$x替换为for循环中的值,还是将其保留为$x?如果是这样的话,for循环的原因是什么?正如我所说的,这将导致脚本认为第一个变量是脚本的结尾。这是一次真正的运行,而脚本并不这么认为。你用的是什么样的系统?你试,linux,bash,Linux,Bash,他们正在逃离他们。也许我误解了这个问题。您希望将$x替换为for循环中的值,还是将其保留为$x?如果是这样的话,for循环的原因是什么?正如我所说的,这将导致脚本认为第一个变量是脚本的结尾。这是一次真正的运行,而脚本并不这么认为。你用的是什么样的系统?你试过这个吗?Bash只保留单引号上下文。因此,脚本中的双引号与其他字符的处理方式相同。没有必要加倍或逃避它们。也许我误解了这个问题。您希望将$x替换为for循环中的值,还是将其保留为$x?如果是这样的话,for循环的原因是什么?嗨,我正在尝试其他


他们正在逃离他们。也许我误解了这个问题。您希望将
$x
替换为for循环中的值,还是将其保留为
$x
?如果是这样的话,for循环的原因是什么?正如我所说的,这将导致脚本认为第一个变量是脚本的结尾。这是一次真正的运行,而脚本并不这么认为。你用的是什么样的系统?你试过这个吗?Bash只保留单引号上下文。因此,脚本中的双引号与其他字符的处理方式相同。没有必要加倍或逃避它们。也许我误解了这个问题。您希望将
$x
替换为for循环中的值,还是将其保留为
$x
?如果是这样的话,for循环的原因是什么?嗨,我正在尝试其他解决方案,我现在正在尝试你的解决方案,它正在拾取编译错误。2编译错误^Cerror:syntax error,意外的'{',意外的'}'''elasticsearch“{^error:syntax error,意外的'}',意外的'}',意外的$End问题中的原始JSON缺少“elasticsearch”键后的
。OMG非常感谢。现在另一个解决方案起作用了。嗨,我正在尝试其他解决方案,我现在正在尝试你的解决方案,它正在收集编译错误。2编译错误^Cerror:syntax error,意外的'{',意外的'}'''elasticsearch“{^error:syntax error,意外的'}',意外的'}',意外的$End问题中的原始JSON缺少“elasticsearch”键后的
。OMG非常感谢。现在,另一个解决方案起作用了。
for x in $(cat raw_tables.txt)
do
echo '{
    "type" : "jdbc",
    "jdbc" : {
        "url" : "jdbc:mysql://localhost:3306/test",
        "user" : "root",
        "password" : "<pass>",
        "sql" : "select * from "'$x'"",
        "elasticsearch" {
                "cluster" : "Search",
                "host": "<ip>",
                "port": 9300
        },
        "index" : ""'$x'"",
        "type": ""'$x'"" 
    }
}' | java \
   -cp "/etc/elasticsearch/elasticsearch-jdbc-2.3.3.1/lib/*" \
   -Dlog4j.configurationFile=/etc/elasticsearch/elasticsearch-jdbc-2.3.3.1/bin/log4j2.xml \
   org.xbib.tools.Runner \
   org.xbib.tools.JDBCImporter


cat raw_tables.txt
table1
table2
table3
while read x; do
  java ... lots of options \
    more options for java \
    and more options for java  <<END_DOC
{
    "type" : "jdbc",
    "jdbc" : {
        "url" : "jdbc:mysql://localhost:3306/test",
        "user" : "root",
        "password" : "<pass>",
        "sql" : "select * from $x",
        "elasticsearch" {
                "cluster" : "Search",
                "host": "<ip>",
                "port": 9300
        },
        "index" : "$x",
        "type": "$x" 
    }
}
END_DOC
done <raw_tables.txt
$ for x in table1 table2 table2; do
> echo 'bla bla bla
>       "index" : "'$x'"
>       bla bla bla'
> done
bla bla bla
      "index" : "table1"
      bla bla bla
bla bla bla
      "index" : "table2"
      bla bla bla
bla bla bla
      "index" : "table2"
      bla bla bla
# This is not JSON itself; it is a filter to be used by jq
# to *generate* JSON.
template='{
        "type" : "jdbc",
        "jdbc" : {
          "url" : "jdbc:mysql://localhost:3306/test",
          "user" : "root",
          "password" : "<pass>",
          "sql" : "select * from \($table)",
          "elasticsearch": {
            "cluster" : "Search",
            "host": "<ip>",
            "port": 9300
          },
          "index" : $table,
          "type": $table
        }
      }'

while IFS= read -r x; do
  jq -n --arg table "$x" "$template" | java ...
done < raw_tables.txt 
template='{
    "type" : "jdbc",
    "jdbc" : {
      "url" : "jdbc:mysql://localhost:3306/test",
      "user" : "root",
      "password" : "<pass>",
      "sql" : "select * from \(.)",
      "elasticsearch": {
        "cluster" : "Search",
        "host": "<ip>",
        "port": 9300
      },
      "index" : .,
      "type": .
    }
  }'

while IFS= read -r x; do
    echo "$x" | jq -R "$template" | java ...
done < raw_tables.txt