1
votes

I created a file name 'testCrontab.php' in /var/www/html folder on amazon ec2, ubuntu-based,

$output = shell_exec('crontab -l');
var_dump($output);

The problem is when I invoked this file in browser it shows

string(207) "0 0,6,12,18 * * * /usr/bin/php /var/www/html/testExec.php 0 3 * * * /usr/bin/php /var/www/html/testCrawlback.php 0 4 * * * /usr/bin/php /var/www/html/testInsertCard.php * * * * * NEW_CRON * * * * * NEW_CRON "

Which I guessed those NEW_CRON are from the other time I tested inserting a new cron from php, but when I invoked this file from command line by issuing /usr/bin/php /var/www/html/testCrontab.php it shows

string(169) "0 0,6,12,18 * * * /usr/bin/php /var/www/html/testExec.php 0 3 * * * /usr/bin/php /var/www/html/testCrawlback.php 0 4 * * * /usr/bin/php /var/www/html/testInsertCard.php"

Also, command crontab -l result in the latter output.

Please help enlighten me what happen here.

1

1 Answers

0
votes

Result will be different because when you are executing script via browser the user will be www-data or nobody. It will show the crons of that user. If you execute the script from command line it will show the crons of that particular user.

Edit

Set cron for webuser

sudo crontab -u webuser -e

List crons of webuser

sudo crontab -u webuser -l

webuser will be nobody or www-data or apache

You can find it by executing the following code from web browser.

 <?php $output = exec('whoami'); 
    echo $output;
 ?>