简体   繁体   中英

shell_exec not working

Here's my command:

sudo /usr/local/bin/jpegoptim --max=50 /home/someuser/public_html/reports/images/r121662.jpg

This command is supposed to compress an image. I tried running this command using backtick operator and shell_exec, neither will work. The file doesn't compress.

But this command runs when I run it directly in the shell logged in as someuser . I've modified sudoers to accept the command without requiring a password. The file is compressed when I run it in the shell.

Apache is configured to run with suPHP, and the PHP files belong to someuser as well. I've further ensured this by writing a test php script just saying system(id); and running it in the browser. That tells me that the script is indeed being run by someuser .

Also, safe_mode is off.

EDIT : Ok, I got it to output the error

sudo: sorry, you must have a tty to run sudo

Now, what does it mean?!

Thanks to Catalin , I was able to get an output. It said sudo: sorry, you must have a tty to run sudo which required requiretty to be disabled for someuser . That is the best solution I got, if there's a way to disable requiretty for a single user calling a single command, please let me know.

sudo typically requires terminal input (ie, must have a tty ) as it will attempt to ask the user for a password before allowing you to execute a command. Do you really need to use sudo to run the command? Try removing the sudo .

尝试使用sudo -S来查看是否将其设置为从stdin读取密码(即使不需要密码)也会绕过tty的测试。

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