1

For Cassandra Database , I run this command ;

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 

Result is like that :

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

I also want to same thing with remote server by ssh command like that :

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"

OR

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"

How could I solve this ?

Thank you

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23

1 Answers1

1

I suspect it's caused by the single quote around week which is already within the context of single quotes (around your select statement).

I think I would try out escaping the single quotes around $week... but you may need to experiment with it a bit

Chris
  • 359
  • 1
  • 8
  • 1
    Why suggest experiments and relay suspicions when there are canonical answers that work 100% of the time available? Check the duplicates for details -- use `declare -f` to serialize functions and `declare -p` to serialize variables into a heredoc ready to pass as stdin to a remote shell. – Charles Duffy Aug 11 '23 at 03:59