How to create a Cron job?

2

I have a real estate website that every day we do an XML import of properties added the day before. This import is made by a component where I choose the file and import it and it runs the function.

I have edited the component for instead of choosing the file, already take direct from a file that is always available with the same name (ex: www.site.com.br/imoveis.xml), updating the XML data automatically every day.

I have no experience with cron jobs, how do I create a schedule for every day it does this import? Or at least the way for me to do it.

    
asked by anonymous 23.10.2017 / 12:59

1 answer

5

The simplest way to do this is:

  • Define what cron will do, what it will handle, either in the database or in files on the server.

  • Create / test scripts with routines and functions that do the manipulations that were initially defined. Example: Create routines that read the available XML and update the values in the database.

  • CRON: To create a scheduled task, do the following:

  • Click the "Cron Jobs" icon in cPanel , under Advanced. Make sure the current email address is valid. Otherwise, enter a new email and click the "Update Email" button.

    Select the setting you want.

    Alternatively, you can adjust the time settings individually. Minute, hour, day, month, and day of the week can be modified to achieve your goal.

    In the input box to the right of "Command, enter the name" of the file type, then add a space and provide the path to the file you want the command to execute. )

    Click the "Add New Cron Job" button. You have just created a cron job to run a file at a certain date and time with the desired repetition.

    Scheduled Tasks are easy to edit and delete. Click the "Cron Jobs" button inside the cPanel. Scroll down to the last section called "Current Jobs Cron." Find the correct cron job and click "Edit" or "Delete" under the actions. Editing does not have good automated tools, so it may be easier to copy the command, delete cron job, and recreate.

    Command line creation. Just examples! sections should be changed.

    PHP

    Command to run a PHP 5.5 cron job:

    /opt/php55/bin/php/home/USUARIO/public_html/arquivo.php
    

    Command to run a cron job PHP 5.4:

    /opt/php54/bin/php/home/USUARIO/public_html/arquivo.php
    

    Command to run a PHP 5.3 cron job:

    /opt/php53/bin/php/home/USUARIO/public_html/arquivo.php
    

    Optional flag sometimes required for a cron job PHP:

    php -q /home/USUARIO/public_html/arquivo. php
    

    Command to use a specific php.ini file:

    php -c /home/USUARIO/public_html/php.ini /home/USUARIO/public_html/arquivo.php
    

    Command to get a remote file:

    /usr/bin/GET http://www.seudomini....br/arquivo.php
    

    Command to run a CGI cron job:

    /home/perl/USUARIO/public_html/cgi-bin/arquivo.pl
    

    SSH Extras

    Command to run a cron shell script job:

    /bin/sh/home/USUARIO/public_html/arquivo.sh
    

    Command to import a database:

    mysql -u mysql_user -p senha database_name < backup.sql
    

    Command to export a database:

    mysqldump -u mysql_user -p senha database_name > backup.sql
    

    Sources:

    link link

        
    23.10.2017 / 15:45