0

I think that it's a permissions problem, because in my script

there are some commands that need root privileges to execute

I added www-data to sudoers hoping it would solve the problem

and did

exec("echo \"passwd\" | sudo -S ./myscript");

in my php but it didn't work.

Thanks

1 Answer 1

4

You could use shell_exec().

shell_exec("echo \"passwd\" | sudo -S ./myscript");

But I'm not sure if it'll work with sudo.

Also I would like to say that adding www-data to sudoers is very dangerous.

Sign up to request clarification or add additional context in comments.

5 Comments

sorry for the typo I meant exec() not 'echo()'... is there a difference regarding permissions with shell_exec()?
There is no difference. The question is why do you need the permissions? What are you trying to achieve? Because in most cases you can just change permissions for particular scripts, files, etc to solve the problem.
I'm trying to run a script that when I execute it from terminal as root (or with sudo) does something that it doesn't do when I call it from exec()... (not very clear I guess : ( I don't have access to the script at the moment)
maybe if I add sudo at the beginning of every command that needs root permissions in the script....?
I'm sorry but I can't help you. I don't know what your script does. "Talk is cheap. Show me the code." - Torvalds, Linus

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.