# Ssh not supporting sudo and sqlplus commands

**URL:** <https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518>\
**Category:** Shell Programming and Scripting\
**Created:** [April 2, 2013, 2:50am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518 "2013-04-02T02:50:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandini](https://community.unix.com/letter_avatar/chandini/32/6_22734026db12803ebb3e059622ac3534.png) [@chandini](https://community.unix.com/u/chandini)\
**Post date:** [April 2, 2013, 2:50am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/1 "2013-04-02T02:50:13Z")

</div>

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.

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

```

ssh command I used here

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![Anamica](https://community.unix.com/letter_avatar/anamica/32/6_22734026db12803ebb3e059622ac3534.png) [@Anamica](https://community.unix.com/u/Anamica)\
**Post date:** [April 2, 2013, 2:54am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/2 "2013-04-02T02:54:26Z")

</div>

Try the command

```nohighlight
sudo /bin/su - username

```

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [April 2, 2013, 3:33am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/3 "2013-04-02T03:33:08Z")

</div>

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

--ahamed

---

<div class="post-metadata">

**Author:** ![chandini](https://community.unix.com/letter_avatar/chandini/32/6_22734026db12803ebb3e059622ac3534.png) [@chandini](https://community.unix.com/u/chandini)\
**Post date:** [April 4, 2013, 3:27am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/4 "2013-04-04T03:27:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [April 4, 2013, 3:40am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/5 "2013-04-04T03:40:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hanson44](https://community.unix.com/letter_avatar/hanson44/32/6_22734026db12803ebb3e059622ac3534.png) [@hanson44](https://community.unix.com/u/hanson44)\
**Post date:** [April 4, 2013, 5:10am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/6 "2013-04-04T05:10:13Z")

</div>

> [@](#):
>
> see the output of which sudo and

"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".

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/6_22734026db12803ebb3e059622ac3534.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [April 4, 2013, 7:14am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/7 "2013-04-04T07:14:47Z")

</div>

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:-

> [@](#):
>
> ```plaintext
> ssh -n user@remote host "cd xx/yy/z; pwd; sudo su - username ;sqlplus user/pwd@db; srvrmgr ;"
> 
> ```

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:-

```plaintext
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

---

<div class="post-metadata">

**Author:** ![chandini](https://community.unix.com/letter_avatar/chandini/32/6_22734026db12803ebb3e059622ac3534.png) [@chandini](https://community.unix.com/u/chandini)\
**Post date:** [April 5, 2013, 8:19am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/8 "2013-04-05T08:19:30Z")

</div>

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

```nohighlight
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

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

```

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/6_22734026db12803ebb3e059622ac3534.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [April 6, 2013, 2:38am UTC](https://community.unix.com/t/ssh-not-supporting-sudo-and-sqlplus-commands/326518/9 "2013-04-06T02:38:08Z")

</div>

If you just run

```nohighlight
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:

```nohighlight
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
