Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing CQL through Shell Script?

I am trying to execute the CQL commands from shell script. I am able to connect to the cqlsh (CQL version i'm using is 1.1.18) but unable to send the queries to cql.

Any ideas or suggestion how to proceed on this? Do I need to connect to Cassandra and execute few commands (select/update ) with shell script ??

like image 794
Immadisetty Avatar asked Aug 13 '14 12:08

Immadisetty


2 Answers

cqlsh -e "select * from ks.table limit 1;" > ~/output 
like image 62
zqhxuyuan Avatar answered Sep 28 '22 03:09

zqhxuyuan


I'm not sure about Cassandra 1.1.18, but you should be able to accomplish this with the -f flag of cqlsh. Let's say have a file of CQL commands called "commands.cql". I can invoke those commands against my local Cassandra instance like this:

$ cqlsh -f commands.cql -u myusername -p mypassword localhost 

If I wanted to invoke that from within a Bash script, the script's code would look something like this:

#!/bin/bash cqlsh -f commands.cql -u myusername -p mypassword localhost 

Save that as an executable file, and run it like any other.

like image 29
Aaron Avatar answered Sep 28 '22 04:09

Aaron