Jump to content

Recommended Cron Jobs and Task Control Using Flags


EIYEI Digital

Recommended Posts

Cron discussions are so scattered that I thought this thread will help a lot of people (including me) to set cron jobs properly and share experiences doing so...

 

First, for all non-tech savvy users, a basic (very basic) view about cron jobs:

 

A Cron is a system (server) daemon (program) used to execute desired tasks (in the background) at designated times. It has 6 well defined parts as you can see:

 

01 04 1 1 1 /home/user/somedirectory/somecommand

 

Where the first 5 groups of digits, tell the cron when to execute the task or command...:

 

In the same order as the example above, from left to right, each group of digits tell:

minute (0-59 /* every minute), hour (0-23, 0 = midnight /* every hour), day (1-31 /* every day), month (1-12 /* every month), weekday (0-6, 0 = Sunday /* every weekday), command

 

So, in the example above somecommand will run every monday of january dated 1st at 4:01am

 

 

According to the WHMCS documentation you should run daily this: (http://docs.whmcs.com/Crons)

 

php -q /home/user/whmcs/crons/cron.php

 

So, in your cPanel > Cron Jobs section, you will have something like:

 

15 7 * * * php -q /home/user/whmcs/crons/cron.php > /dev/null 2>&1

 

Let's see that part by part:

 

15 7 * * * means that it will run on the minute 15, of the hour 7, every day, every month every weekday, in plain english, every day at 7:15am (server time).

 

It will execute the command php -q /home/user/whmcs/crons/cron.php

 

php -q means it will use php and will do it quietly (-q)

 

And the last bit > /dev/null 2>&1, tells the cron not to show/generate any output of the command, so you don't receive endless emails with the detail of the execution.

 

Done with the basic technical part... So for the practical day-to-day implementation..

 

 

Cron Flags (task control) (http://docs.whmcs.com/Cron_Tasks)

 

I've been struggling to run cron.php with the flag skip_backups, every time it runs, the backup gets generated.

 

That is php -q /home/user/whmcs/crons/cron.php skip_backups

 

Why would I like to do that? Well, I want to run the main cron once a day (or do you recommend something else) and backup my database twice a day...

 

 

I have seen a couple of posts where, for example, we want to skip suspensions during weekends, so you can deal with them during office hours mon-fri. Makes sense!

 

So, you would run, for your daily cron task something like:

 

daily:

15 7 * * * php -q /home/user/whmcs/crons/cron.php skip_suspensions

 

and for your suspensions alone:

 

suspensions:

15 8 * * 1-5 php -q /home/user/whmcs/crons/cron.php do_suspensions

 

 

Also, someone suggested to skip invoicing during weekends and do it the next working day (monday), so it would be something like (following the previous example):

 

daily:

15 7 * * * php -q /home/user/whmcs/crons/cron.php skip_suspensions skip_invoices

 

and for your suspensions+invoicing alone:

 

suspensions+invoicing:

15 8 * * 1-5 php -q /home/user/whmcs/crons/cron.php do_suspensions do_invoices

 

 

So, here my requests... if you'd like to help, leave your recommended cron tasks, everything from your experience will for sure help someone else...

 

And, why is my skip_backups flag not working? I checked the documentation and couldn't find any troubleshooting information on this... http://docs.whmcs.com/Cron_Job_Issues

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated