0

I just wanted to run all my cronjob manually and immediately, following command works well in command line terminal but not working with shell_exec

crontab -l | grep -v '^#' | cut -f 6- -d ' ' | while read CMD; do eval $CMD; done

Can anyone please help me how can I merge this with php, I tried as following but not working:

shell_exec('crontab -l | grep -v "^#" | cut -f 6- -d " " | while read CMD; do eval $CMD; done');

One more thing, I just wants to trigger without bothering about output and waiting.

I have also tried creating shell script: cron.sh and tried: shell_exec('sh cron.sh'); Still no success

  • I have created one shell script and placed that command inside, and running shell_exec('sh xyx.sh') but still no success – minc Jan 25 '16 at 11:14
0

Are you using this php script whit apache ? In this case you should check if apache has the rights to exec those crontabs.

Maybe $CMD is not being well parsed, php and bash use the same syntax for the variables... Who is interpreting this?

Also I would recommend you to use the exec function instead, so you can debug a little more with the output and return code.

Good luck!

  • Yes I am using apache lampp, and how can i check for that – minc Jan 25 '16 at 11:00
  • I have created one shell script and placed that command inside, and running shell_exec('sh xyx.sh') but still no output – minc Jan 25 '16 at 11:13
  • Apache runs under the apache user or www-data user. This user is not capable to run commands who need root rights. If you need to run such command, you have to use sudo. check: blogmotion.fr/systeme/… (sorry, is in french) – uDalillu Jan 25 '16 at 14:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.