Skip to content
Home » Unix » SSH Remote "Command not found"

SSH Remote "Command not found"

Remote: command not found

Tried to execute a command on a remote server simply by using SSH tunnel, but it failed with "command not found".

Bash

In Linux, we saw command not found.

[grid@primary01 ~]$ ssh primary02 "lsnrctl status"
bash: lsnrctl: command not found

Ksh

In AIX, we saw a similar message.

[grid@primary01 ~]$ ssh primary02 "lsnrctl status"
ksh: lsnrctl: not found.

Let's see what manual says about it.

[grid@primary01 ~]$ man ssh
...
     If a command is specified, it is executed on the remote host instead of a login shell.

Which means that we didn't login the remote shell to execute the command.

Solution

To reach our goal, we should set environment by sourcing the profile by a dot command before executing the command.

Bash

For bash shells, we should source .bash_profile.

[grid@primary01 ~]$ ssh primary02 ". ~/.bash_profile; lsnrctl status"

Ksh

For ksh shells, we use .profile.

[grid@primary01 ~]$ ssh primary02 ". ~/.profile; lsnrctl status"

Please note that, the first dot command is the same as the command source.

Leave a Reply

Your email address will not be published. Required fields are marked *