Uday Reddy
Uday Reddy

Reputation: 1471

error when cassandra-cli command executed in ssh

I have two servers A and B, I have a shell script in serverA which logs into serverB (through ssh) and runs the following command:

sh cassandra-cli -h <serverB> -v -f database_import.txt;

so when I do this manually, I follow these steps:

serverA:~$ ssh serverB
serverB:~$ sh cassandra-cli -h <serverB> -v -f database_import.txt;

It works properly when I follow these steps manually but when I automate this process in a shell script by this following line:

serverA:~$ssh serverB "sh cassandra-cli -h <serverB> -v -f database_import.txt;"

I get this error,

cassandra-cli: 46: cassandra-cli: -ea: not found

Upvotes: 0

Views: 439

Answers (1)

Aleks-Daniel Jakimenko-A.
Aleks-Daniel Jakimenko-A.

Reputation: 10653

So, as you already pointed out, $JAVA is empty through ssh.

This is because .bashrc is not sourced when you log in using ssh. You can source it like this:

. ~/.bashrc

And your command is going to look like this:

ssh serverB ". ~/.bashrc; sh cassandra-cli -h <serverB> -v -f database_import.txt;"

You can also try placing this into your .bash_profile instead of invoking it manually each time.

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

Upvotes: 2

Related Questions