如何将变量传递到远程 SSH 会话?

问题描述 投票:0回答:1

对于 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"

我该如何解决这个问题?

谢谢你

linux bash cassandra cql cqlsh
1个回答
2
投票

我怀疑这是由 week 周围的单引号引起的,它已经在单引号的上下文中(在您的 select 语句周围)。

我想我会尝试转义 $week 周围的单引号...但你可能需要稍微尝试一下

© www.soinside.com 2019 - 2024. All rights reserved.