Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo: command not found

I am trying to execute screen as another user using sudo.

I'm using the command:

echo 'userpassword' | /usr/bin/sudo -u 'myuser' -S '/usr/bin/screen -ls'

Any help found on the internet says that the sudo clears the environment variables (like PATH). So I decided to use the full path to the applications but I'm still getting the command not found error.

Error:

sudo: /usr/bin/screen -ls: command not found

Sudo is installed on the system. Screen is installed on the system.

For sudo, I have tried the -E and -H flag but it doesn't help.

I tried to set PATH variable using something like this:

... | /usr/bin/sudo -u 'myuser' -S 'env PATH=$PATH; /usr/bin/screen -ls'

Supposedly the $PATH was suppose to expand before the command executes but I was getting other errors...

Can someone provide a command that will let me execute commands as another user and explain what each part of the command does so I can understand it?

Thanks.

like image 825
Bradley Odell Avatar asked Feb 06 '23 13:02

Bradley Odell


1 Answers

Try,

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

Probably you replaced the path variable while trying to set a new path variable.

Going forward, do 'echo $PATH' before adding a new path variable.

like image 165
Siena Avatar answered Feb 09 '23 04:02

Siena