Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create, Edit and Delete Crontab Jobs

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 308
    Comment on it

    Hello readers, today we will discuss about Crontab jobs.

    Q. What is crontabs?

    Ans- Cronjob is a service or we can say its a tool that run in backend periodically at fixed times, dates, or intervals.

    The crontab is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list. crontab stands for "cron table," because it uses the job scheduler cron to execute tasks.

    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)
    
    <?php
    $output = shell_exec('crontab -l');
    file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
    echo exec('crontab /tmp/crontab.txt');
    ?>
    

    The above can be used for both create and edit/append

    To delete jobs:

    echo exec('crontab -r');
    

    Note: apache is running as a particular user and that's usually not root, which means the cron jobs can only be changed for the apache user unless given crontab -u privilege to the apache user.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: