Trying to manipulate cronjobs using php

Posted on

Trying to manipulate cronjobs using php – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, php, cron, httpd, .

Good day,

Im trying to create a script to add, remove and list cronjobs inside the servers using php. Whenever I run the command like this php cronjobs.php the output is correct , but if i call it from inside the website, it gives back an empty result!

Heres my code for cronjobs.php:

$output = shell_exec('~/');
echo "$output";

And here is my code for

crontab -l > cronjobs.log

Any ideas???


Solution :

Im trying to create a script to add, remove and list cronjobs

There are security implications to what you are asking.

You are essentially allowing a user to run programs as anyone (even as root) on your server from a web interface via php.

You can do it

You could look into using sudo (see man sudo and /etc/sudoers) to enable apache to execute crontab as root. Just be really careful.

Leave a Reply

Your email address will not be published. Required fields are marked *