简体   繁体   中英

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.

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.

似乎没有必要将命令封装在引号中,没有它们甚至可以工作。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM