SLSCoder Posted December 31, 2021 Share Posted December 31, 2021 Ubuntu 20.04 apache2 php 8.0.14 php-fpm I'm trying to execute an at command from php. The code is: $out = shell_exec('echo mkdir /var/www/test | at now +1 minutes'); echo $out . "<br>"; If I run that command from the command line it works fine. When I run it from php I get nothing back into the $out variable and no directory is created. How can I run an at command from php? Quote Link to comment https://forums.phpfreaks.com/topic/314374-i-cant-add-an-at-command-from-php-please-help/ Share on other sites More sharing options...
SLSCoder Posted December 31, 2021 Author Share Posted December 31, 2021 I should add that: The file /etc/at.deny does not include www-data (which is $_Server["user"]) The file /etc/at.allow does include www-data. Quote Link to comment https://forums.phpfreaks.com/topic/314374-i-cant-add-an-at-command-from-php-please-help/#findComment-1593100 Share on other sites More sharing options...
Solution SLSCoder Posted December 31, 2021 Author Solution Share Posted December 31, 2021 I figured this out. The problem was not with the at command, the user www-data did not have permissions to create the directory. This is resolved. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314374-i-cant-add-an-at-command-from-php-please-help/#findComment-1593104 Share on other sites More sharing options...
gizmola Posted January 7, 2022 Share Posted January 7, 2022 A couple of notes/suggestions for you: First, shell_exec is equivalent to using backtics, inherited from the bourne bash shell. $out = `echo mkdir /var/www/test | at now +1 minutes`; I can see you have a contrived example, but if you actually want to depend on os return codes from the command you have to use exec, as it allows for the passing of an optional return code parameter, which in many cases is probably a preferable way to determine whether your commands ran successfully or had errors. Quote Link to comment https://forums.phpfreaks.com/topic/314374-i-cant-add-an-at-command-from-php-please-help/#findComment-1593225 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.