Ssh not supporting sudo and sqlplus commands

Hi Guys ,

I was facing an issue some thing like , I have to connect remote machine and should execute few commands over there , I am able to run some simple commands , but below commands are throws error like not found.

eg : sudo su - username  and sqlplus user/pwd@db , srvrmgr commands etc 

ssh command I used here

ssh -n user@remote host "cd xx/yy/z; pwd; sudo su - username ;sqlplus user/pwd@db; srvrmgr ;" 

fyi I tried to run with separate script which I keep in remote machine , but no luck .

Please suggest/help me if any other ways to resolve this issue.

Regards
Chandini

Try the command

sudo /bin/su - username

It will be better if you can post the errors.
Doesn't sudo su - username need a password?

--ahamed

Hi Anamika , It's not working
I tried with sudo /bin/su - username from remote machine ..but showing error same

bash: sudo: command not found

Looks like the PATH env variable is not available. Log into the remote host and see the output of which sudo and then try using sudo with absolute path in your ssh command.

--ahamed

"which" depends on the PATH, so that won't work, if sudo is not in the PATH.

Check if sudo is installed, using whatever package manager you have.

Or try "find / -name sudo" or "find /usr -name sudo".

You will need to set up the profile of the user account you are ssh connecting with initially so that the PATH includes when the sudo command is, or you could fully qualify it in your command.

I would suggest that this has it's own problems:-

The section that has the sudo su - username in it is just that. It will switch user and sit at a prompt. If you want to run sqlplpus or whatever, you need to supply that as arguments, such as:-

ssh -n user@remote host "cd xx/yy/z; pwd; sudo su - username \"sqlplus user/pwd@db\""

I have highlighted in green the escaped quotes. They need to be escaped because they are within the quoted command that the ssh is sending.

I hope that this helps
Robin
Liverpool/Blackburn
UK

Thx for reply
Tried the same ..but showing the same error

ssh -n user@host " cd /u01/app/oracle/siebel/siebsrvr/bin; pwd ;sudo su - oracle \"sqlplus user/pwd@dbname\";echo "test-complete";"

results of above command is

/u01/app/oracle/siebel/siebsrvr/bin
test-complete
bash: sudo: command not found

If you just run

ssh -n user@host " cd /u01/app/oracle/siebel/siebsrvr/bin; pwd ;sudo su - oracle \"sqlplus user/pwd@dbname\";echo "test-complete";"

then there are still two problems.

Firstly the sudo command is still not on the path. You may need to fully qualify it. Can you share the output from:

ssh -n user@host " cd /u01/app/oracle/siebel/siebsrvr/bin; pwd ; echo $PATH ; ps -f"

THis will give us the shell, of the remote user too. Feel free to sanitise anything sensitive.

You also don't do anything within your SQL session. This is likely to wait for input so your command may appear to hang. Do you have some SQL to run that you can call in from the command line?

Let us know how you get on.

Robin