您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用PHP创建,编辑和删除crontab作业?

使用PHP创建,编辑和删除crontab作业?

usage:  crontab [-u user] file
        crontab [-u user] [ -e | -l | -r ]
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

所以,

$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');

如果用户具有足够的文件写入权限,则以上内容可用于 。

echo exec('crontab -r');

另外,请注意,apache以特定用户身份运行,并且通常不是root用户,这意味着cron作业只能为apache用户更改,除非为apache用户赋予了crontab -u特权。

php 2022/1/1 18:19:33 有397人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶