S
S
Sergey2015-08-20 08:16:26
linux
Sergey, 2015-08-20 08:16:26

Why does a sudo script work fine but not as root? How is this possible?

There is one sh script. And he requires root rights. Works fine through sudo, but if you run the script as root, then a couple of errors fly out in the process. And I can't understand how this is possible, because sudo and root must have the same rights. What could be the reason in theory?
The script does not execute rename and\or rpl commands, which is why it does not find the necessary paths for files later, and everything is fucked up. But everything works through sudo.
What's the magic? It seems to me some kind of chroot jail on the servers, something is blocking the external. I can't find any other explanation.
Tell me, otherwise I'll go crazy.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2015-08-20
@butteff

sudo - execute a command on behalf of another user,
but the root environment variables are superimposed on the current ones.
If you log in as root, you may be missing something in PATH or in some other necessary variable.

A
Azazel PW, 2015-08-20
@azazelpw

Well, you wrote correctly, provide a script, it will be easier to figure it out.
I'm not a telepath but I'll try to help you.
Start your script like this.
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question