To access "Cron jobs" menu, sign into DirectAdmin and then click on the "Advanced Features" icon, followed by the "Cron Jobs" link.

Cron jobs are system commands that can be scheduled to run automatically at a certain time.  
For example, if you wanted a "hi" value added to a text file every Monday morning, you could do this through the cron jobs menu.
Values that can be set are minute, hour, day, month, and day of the week (Monday-Sunday; the numbers 0 or 7 represent Sunday). Any value can be ignored by placing an asterisk (*) in the text field.

DirectAdmin cron jobs


In the above example, we are setting command echo to put word "hi" in hi_per_hour.txt file every day at midnight.

You can also specify exact times using commas to separate them (e.g. 1,2,3 is minutes 1, 2 and 3).

You can specify spans using a dash (e.g. 5-7 is minutes 5 to 7).

You can specify intervals using a star and a forward slash. (e.g.: */2 is every 2nd minute.)

You can combine them to create a more precise schedule. (e.g.: 1,5,11-15,30-59/2 (minutes 1, 5, 11 to 15 and every 2nd minute between 30 and 59).

Remember to click the "Create" button below when you are finished entering your data.

If you're trying to run a php script, remember to run the php binary, and pass it the php script. For example:

/usr/local/bin/php /home/user/domains/domain.com/public_html/file.php

 

Debug Tricks for Cron Jobs

Debugging is never an easy task, and it may be even harder when you need to debug a script run by cron.

When you need to test and debug a cron, you can:

  • set the timing of your cron task to * * * * *
    Doing so, it will run every minute, and you'll not need to wait a long time to see the results.

  • crontab has it's own environment, which might differ from the environment you set.
    So, i.e., if you set special PHP configuration using .htaccess, it may be ineffective for your cron script.

    So, check environment configuration inside your own script (i.e., inserting a phpinfo() command).

  • pipe all the output of your script to a file, that you'll be able to later access in File Manager or via FTP.
    You can do it using following code to run your cron job:
    * * * * * /path/to/script.sh >> ~/crontask.out 2>&1
    and later checking the content of file crontask.out

 

Found this article interesting?
Subscribe to DomainRegister´s newsletter!

You can unsubscribe at any time by simply clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp s privacy practices here.

  • DirectAdmin, php
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

 Come visualizzare le statistiche del sito (log e Webalizer)

Nota: questa guida si applica a tutti i nostri piani hosting Linux shared (Basic, Starter Cloud,...

 Come abilitare la compressione gzip sul proprio sito

Nota: questa guida si applica a tutti i nostri piani hosting Linux shared (Basic, Starter Cloud,...

 Ho caricato il mio sito, però continuo a vedere la pagina di cortesia: perchè?

La pagina di cortesia creata automaticamente per ogni servizio di hosting Linux è un file...

 How to Install a SSL certificate on DirectAdmin

To install in DirectAdmin a commercial SSL certificate you have just issued, you need:...

 Come effettuare un collegamento FTP per gestire il proprio sito

L'interfaccia di gestione DirectAdmin, utilizzata per tutti i nostri piani hosting Linux e Cloud,...