You get a bonus - 1 coin for daily activity. Now you have 1 coin

shell_exec(cd /home/user/scripts/; sudo su ./testsh.sh) doesn't work; NULL

Practice




not working
$result = shell_exec('cd /home/user/scripts/; sudo su ./testsh.sh');

returns NULL

add 2>&1 to the command

shell_exec('cd /home/user/scripts/; sudo su ./testsh.sh 2>&1');

it says
sudo: no tty present and no askpass program specified

add and
check the whole line
www-data ALL=(root) NOPASSWD: /home/user/script/test.sh

to the file
/etc/sudoers

thanks, it worked

don't forget to set the directory where the script is located

sudo su
it's better to write it without SU


Redy]2>&1
means
output to console including all errors
2 redirected to stream 1

0 — STDIN, 1 — STDOUT and 2 — STDERR

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)