Search code examples
makefilecassandracqlcqlshiterm2

'No such file or directory' when running Makefile script


The folder structure is set up like so:

Main directory
  \_ keyspaces
    \_ f1
      \_ bootstrap.cql
      \_ anotherFolder
        \_ 0001-something.cql
    \_ f2
      \_ bootstrap.cql
      \_ anotherFolder
        \_ 0001-something.cql
        \_ 0002-moreSomething.cql

I have a Makefile in the main directory which contains this code:

do_stuff:
    for ks in keyspaces/*; do \
        cqlsh -f "$${ks}/bootstrap.cql"; \
    done

When I run make do_stuff from my terminal (using iTerm2) inside of the main directory, I get an error, stating the following:

Can't open 'keyspaces/f1/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f1/bootstrap.cql'
command terminated with exit code 1
Can't open 'keyspaces/f2/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f2/bootstrap.cql'
command terminated with exit code 1
make: *** [do_stuff] Error 1

However, if I run this in my terminal: cat keyspaces/f1/bootstrap.sql I get the contents of that file printed out, so the path is correct and it does exists, but cqlsh can't recognize it?

Looking at the Cassandra/cqlsh docs, it looks like I'm using the -f command properly, so I don't know why I'm getting the errors.


Solution

  • I would start with simple steps to eliminate potential issues

    .
    ├── Makefile
    └── keyspaces
        ├── f1
        │   └── bootstrap.cql
        └── f2
            └── bootstrap.cql
    

    with following Makefile, works fine

    do_stuff:
        for ks in keyspaces/*; do \
            cat "$${ks}/bootstrap.cql"; \
        done
    

    execution

    make
    for ks in keyspaces/*; do \
          cat "${ks}/bootstrap.cql"; \
        done
    a
    b
    

    Double check, that inside Main directory you can call

    cqlsh -f "keyspaces/f1/bootstrap.cql"
    

    Maybe you can delegate this to find?

    do_stuff:
        find `pwd` -name "*.cql" -exec cat {} \;