Question

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
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top