cassandra 如何将变量传递给远程SSH会话?[副本]

fnatzsnv  于 2023-10-18  发布在  Cassandra
关注(0)|答案(1)|浏览(140)

此问题已在此处有答案

Passing variables to SSH [duplicate](2个答案)
Command line Parameters in bash shell script in nested ssh(2个答案)
Passing external shell script variable via ssh(2个答案)
Passing a variable to a remote host in a bash script with ssh and EOF [duplicate](2个答案)
2个月前关闭。
对于Cassandra数据库,我运行以下命令:

export week='202328'

cqlsh -u $DSE_USERNAME -p $DSE_PASSWORD 
    -e "select backup_id,week,event_time,type,status from \"Opscenter_XXXXX\".backup_reports where week = '$week' and type='backup' LIMIT 1  ALLOW FILTERING ;" | tail -n +4 | head -n -2

结果是这样的:

Opscenter_76a7068a-b567-4458-bdc8-3899253c32a2_2023-07-16-15-00-00-UTC | 202328 | 2023-07-16 15:00:00.000000+0000 | backup | success

我也想通过ssh命令对远程服务器做同样的事情:

export week='202328'

ssh -q -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o BatchMode=yes $user@$host ". .bash_profile ;cqlsh -u $user -p  $password   -e 'select backup_id,week,event_time,type,status from \"Opscenter_XXXXX\".backup_reports where week = **'$week'**   LIMIT 1 ALLOW FILTERING ;'  | tail -n +4 | head -n -2  > lastbackup.txt"

<stdin>:1:InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid INTEGER constant (202328) for "week" of type text"

ssh -q -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o BatchMode=yes $user@$host ". .bash_profile ;cqlsh -u $user -p  $password   -e 'select backup_id,week,event_time,type,status from \"Opscenter_XXXX\".backup_reports where week = **$week**   LIMIT 1 ALLOW FILTERING ;'  | tail -n +4 | head -n -2  > lastbackup.txt"     

<stdin>:1:InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid INTEGER constant (202328) for "week" of type text"

我该怎么解决这个问题?
谢谢你

06odsfpq

06odsfpq1#

我怀疑这是由周周围的单引号引起的,它已经在单引号的上下文中(围绕您的select语句)。
我想我会尝试在$week左右转义单引号。但你可能需要尝试一下

相关问题