Zeng Huang
Zeng Huang

Reputation: 69

When I use ssh to start remote program, error can't find shared libraries

I want to write a script to start the remote program, like this ssh user@ip "/home/xx/remote_program"(I used ssh-copy-id first).

I tested using ssh user@ip "date", and I can get the remote date time. And I can ssh user@ip, then ./remote_program, to start remote_program, run ok.

But when I use ssh user@ip "/home/xx/remote_program", it tells me an error while loading shared libraries: libxmlrpcpp.so: cannot open shared object file: No such file or directory`.

I test to use ssh user@ip "echo $PATH and ssh user@ip "echo $LD_LIBRART_PATH", the output same as ssh user@ip then echo $PATH echo $LD_LIBRARY_PATH.

How can I start a remote program whit ssh script?


Thanks, @user1934428, you give me some inspiration.

I tested printenv | grep LD_LIBRARY_PATH, and there have many outputs, but when I use ssh user@ip "printenv | grep LD_LDBRARY_PATH", the output is empty.

Today I did more tests.

I write a script in the remote machine,start.sh

#!/bin/bash
source env.sh
cd build
./demo

If I execute /home/xx/demo_dir/start.sh in remote machine, run is ok.

But if i execute ssh user@ip "/home/xx/demo_dir/start.sh", it tells me

/home/xx/demo_dir/start.sh: line 2: env.sh: No such file or directory
/home/xx/demo_dir/start.sh: line 3: cd: build: No such file or directory
/home/xx/demo_dir/start.sh: line 4: ./demo: No such file or directory

I'm confused about that, just like this command was executed in my local machine, not in the remote machine.

Upvotes: 0

Views: 771

Answers (1)

Zeng Huang
Zeng Huang

Reputation: 69

I find the real reason for this phenomenon when I use the ssh user@host command, the bash mode is non-interactive + non-login shell.

So I fix my command like this

ssh user@host "source ~/.profile; source ~/.bashrc; cd /home/xx/test; source env.sh; cd build; ./demo;"

Run ok.

Upvotes: 1

Related Questions