I want to access the root crontab from webpage.How i can do that.I have a project in which i have to list all the jobs on webpage.And after that if needed we need to edit the time for cronjobs configured.
Please help me with this.
I want to access the root crontab from webpage.How i can do that.I have a project in which i have to list all the jobs on webpage.And after that if needed we need to edit the time for cronjobs configured.
Please help me with this.
Use visudo and add
`APACHEUSER ALL=NOPASSWD: /usr/bin/crontab`
APACHEUSER is the user apache runs under like www-data or apache
/usr/bin/crontab is the path to crontab, you can try which crontab
to find the path
<?php
$result = shell_exec('sudo -u root -S crontab -l 2>&1'); // 2>&1 allows you to get stderror
echo $result;
file_put_contents('/tmp/crontab.txt', $result.'* * * * * /path_to_cron'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
?