How to create a scheduled CRON task in linux

0

I have a scheduled task that executes a script in php and it verifies me in MYSQL database if there are other tasks programmed and what is its status.

I understand that to create a task I must do the following crontab -e in the linux command line and edit the file but what I'm looking for is to add a new crontab task from the same php code.

    
asked by Arielperez 03.11.2018 в 16:47
source

1 answer

0

When you run the crontab -e command, you edit a file in /var/spool/cron/{usuario} , where {usuario} is the username that executes the command.

Knowing this, you can execute the commands from PHP to add the scheduled tasks that you need in the crontab, something like this:

<?php
$tarea = "00 12 * * * scriptEjecutar.php";
$usuario = "usuarioLinux";
//Agrega al archivo
echo exec("echo '$tarea' >> /var/spool/cron/$usuario");
//Instala el nuevo crontab
echo exec("crontab /var/spool/cron/$usuario");
?>
    
answered by 03.11.2018 в 17:58