pcalcao
pcalcao

Reputation: 15988

cqlsh equivalent to mysql -e

I'm trying to create a small shell script where it would be very handy for me to run a command directly from the command line via cqlsh.

In MySQL I could do something like:

mysql -u root  -e "show databases;"

Is there a cqlsh equivalent to -e, or is the closest equivalent putting whatever commands I want to run in a file and use -f?

Thanks

Upvotes: 5

Views: 2510

Answers (2)

Aaron
Aaron

Reputation: 57843

For just a one-shot command, cqlsh 4.1.1 also has a -e option:

$cqlsh -e 'desc keyspaces' -u myusername -p mypassword localhost

branch     stackoverflow  products  system_auth  
customers  system         branches  system_traces

If you have something complicated, like a multi-line sequence of commands, then the -f option on cqlsh should be what you want to do. To demo, I'll create a simple cql script file called descTables.cql which looks like this:

$ cat descTables.cql
use stackoverflow;
desc tables;

Now, I'll invoke that cql script with cqlsh -f:

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

datasimple  items

FYI- It looks like the most-recent version of 2.0 has cqlsh 4.1.1, which has the -e flag. On one of my instances, I have 4.1.0 and the -e option is not available.

Upvotes: 5

kkmishra
kkmishra

Reputation: 709

There are more options they are listed below:

  1. "-C", "--color", action='store_true', dest='color', help='Always use color output'
  2. "--no-color", action='store_false', dest='color', help='Never use color output'
  3. "-u", "--username", help="Authenticate as user."
  4. "-p", "--password", help="Authenticate using password."
  5. '-k', '--keyspace', help='Authenticate to the given keyspace.'
  6. "-f", "--file", help="Execute commands from FILE, then exit"
  7. "-t", "--transport-factory", help="Use the provided Thrift transport factory function."
  8. '--debug', action='store_true', help='Show additional debugging information'
    1. '--cqlversion', default=DEFAULT_CQLVER, help='Specify a particular CQL version (default: %default).'' Examples: "3.0.3", "3.1.0"'

Upvotes: 0

Related Questions