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.
使用 visudo 并添加
`APACHEUSER ALL=NOPASSWD: /usr/bin/crontab`
APACHEUSER 是 apache 运行在 www-data 或 apache 下的用户 /usr/bin/crontab 是 crontab 的路径,你可以尝试which crontab
找到路径
<?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');
?