Last active
February 3, 2020 06:59
-
-
Save FatihGoktas/fed2ed39ab0a0cff27b9ae16de62761d to your computer and use it in GitHub Desktop.
Add crontab command to server by PHP script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you will see nothing here | |
$output = shell_exec('crontab -l'); | |
echo "Before<br>"; | |
var_dump($output); | |
echo "<hr>"; | |
// Create a temporary file and put into our crontab command line | |
// I wrote an order that will work every minute | |
file_put_contents('/tmp/crontab.txt', $output.'1 * * * * curl http://example.com/test_1.php'.PHP_EOL); | |
// Should run our temporary file | |
echo exec('crontab /tmp/crontab.txt'); | |
// Let's have a look our crontab job list | |
$output = shell_exec('crontab -l'); | |
echo "After<br>"; | |
var_dump($output); | |
echo "<hr>"; | |
exit(); | |
/* | |
* If you want to check crontab list in terminal | |
* must to login by www-data, follow these commands; | |
* su -s /bin/bash www-data | |
* crontab -l | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment